急救!Android Fragment布局中的FitsSystemWindows=true无效!
我用的是ViewPage+Fragment想要做到把UI内容显示在Status bar上,
发现把状态栏透明后Toolbar就和状态栏重叠了,
然后我就加了FitsSystemWindows=true这行代码但是没有任何效果,
我试过加载Activity的布局中效果是有的,布局会自动空出一个Status bar
大小的PaddingTop但在Fragment布局中就是没有效果,
不管是加在根布局还是子布局中都无效。我只有自己在Toolbar中写上一个
PaddingTop才能让它们不重叠,不过这是偏方。。。。
布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/home_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f1f5f6"/>
<android.support.v7.widget.Toolbar
android:id="@+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<android.support.v7.widget.SearchView
android:id="@+id/home_searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
app:defaultQueryHint="请输入菜品或用户"
app:iconifiedByDefault="false"/>
</android.support.v7.widget.Toolbar>
</RelativeLayout>