android – 设置子视图以适合系统窗口

我正在设置一个简单的视图,它只包含一个空的RelativeLayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:background="@color/red"/>

使用这个主题:

<style name="FullscreenTheme" parent="BaseTheme">
    <item name="android:textColorSecondary">@android:color/white</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

这在onCreate中:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

这导致预期的效果:

《android – 设置子视图以适合系统窗口》

但是,当我尝试添加一个孩子时,我无法让它做同样的事情. XML看起来像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:background="@color/red">

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/bit_teal"
        android:fitsSystemWindows="true"
        android:clipToPadding="false"/>

</RelativeLayout>

这是它的样子:

《android – 设置子视图以适合系统窗口》

有任何想法吗?

最佳答案 摆脱来自RelativeLayout的android:fitsSystemWindows =“true”.我不认为两者都可以同时适合系统视图,并且父级将始终具有子级的优先级(ren)

点赞