使用 22.2.1 设计支持库和 API 22(尚未在早期版本上进行测试),我在片段之间切换时遇到了状态栏填充问题。初始片段加载良好,但在片段事务之后,状态栏填充消失,将所有视图推到不应该出现的位置。弹出返回堆栈后,原始片段也会发生同样的情况。旋转设备可以修复该问题,就像打开软键盘一样(但仅限纵向,横向不适用)。
初始加载或旋转后的主片段(所需)
后压后的主要片段
加载时的其他片段
旋转或键盘后的其他片段(所需)
主要片段:
<android.support.design.widget.CoordinatorLayout
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:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainFragment">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
style="@style/RecyclerView"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/Fab"
android:src="@drawable/ic_person_add_white_24dp"
app:backgroundTint="@color/accent_dark"
app:borderWidth="2dp"/>
第二个片段:
<android.support.design.widget.CoordinatorLayout
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:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/card_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/collapsingToolbar_height"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="@dimen/default_margin"
app:expandedTitleMarginEnd="@dimen/sheet_expanded_title_margin"
app:expandedTitleMarginStart="@dimen/sheet_expanded_title_margin"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/default_tab_layout_height"
app:tabGravity="center"
app:tabMinWidth="120dp"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/Fab"
android:src="@drawable/ic_add_white_24dp"
app:backgroundTint="@color/accent_dark"
app:borderWidth="2dp" />
主题将 windowDrawsSystemBarBackgrounds 设置为 true,将 statusBarColor 设置为透明。
解决了,感谢克里斯·贝恩斯.
问题是它不知道窗口插入。您必须在 onViewCreated 中请求ApplyInsets。
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ViewCompat.requestApplyInsets(coordinatorLayout);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)