You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 14(API 36)Pixel设备浅色模式下状态栏上方空白区域的修复咨询

Android 14(API 36)Pixel设备浅色模式下状态栏上方空白区域的修复咨询

大家好,我最近遇到一个挺棘手的问题,想请教下各位同行:

问题现象

  • 在Android模拟器的Pixel设备上运行App时,浅色模式下状态栏上方会出现一块奇怪的白色空白区域,深色模式下就完全正常(因为App背景本身是黑色);但这个问题只在Pixel设备上出现,其他品牌的设备测试下来都没这个情况。
  • 版本关联:我的项目compileSdk和targetSdk都设置为36(对应Android 14)。当我把API版本降到35,同时在主题配置里添加<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>时,这块空白就会变成黑色,显示恢复正常。但切回API36后,白色空白又会出现。

我尝试过的解决方法

  • 试过在布局中添加一个全屏的View并设置背景为黑色,这个方法对部分布局有效,但不是所有页面都能解决问题。
  • 目前的布局和代码配置:
    • 主布局activity_main.xml的根布局是ConstraintLayout,设置了android:background="@color/white"和android:fitsSystemWindows="true"
    • 在MainActivity中调用了WindowCompat.setDecorFitsSystemWindows(window, true)

相关代码细节

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.appcompat.widget.SearchView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="12dp"
        android:id="@+id/search"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:iconifiedByDefault="false"
        app:searchHintIcon="@null"
        app:queryHint="Search..."
        android:focusable="false"
        app:closeIcon="@drawable/icon_clear"
        app:searchIcon="@drawable/search_icon"
        android:background="@drawable/search_bkg"/>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/recyclerView"
        android:background="@color/white"
        android:layout_marginTop="12dp"
        app:layout_constraintTop_toBottomOf="@id/search"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

    <TextView
        android:id="@+id/noResultsMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_results_found"
        android:visibility="gone"
        android:textSize="18sp"
        android:textColor="@android:color/darker_gray"
        android:padding="16dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity 相关代码

WindowCompat.setDecorFitsSystemWindows(window, true)

想请教下各位,这个问题应该怎么针对性解决?是不是我代码里的某个设置存在冲突?麻烦大家帮忙分析下,非常感谢!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 12:28:02