2015-11-06 37 views
2

我设立这只是包含一个空的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); 
} 

这导致了预期的效果:

enter image description here

但是,当我尝试添加一个孩子时,我无法让它做同样的事情。该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> 

这里是什么样子:

enter image description here

任何想法?

回答

0

摆脱RelativeLayoutandroid:fitsSystemWindows="true"。我不认为两者都可以同时适合系统视图,并且父母始终优先于孩子(ren)