我正在设置一个简单的 View ,它只包含一个空的 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);
}
这会产生预期的效果:
但是,当我尝试添加一个 child 时,我无法让它做同样的事情。 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>
这是它的样子:
有什么想法吗?
最佳答案
从 RelativeLayout
中删除 android:fitsSystemWindows="true"
。我认为两者不能同时符合系统观点,父总是优先于子(ren)
关于android - 设置 subview 以适应系统窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33573443/