2016 年 1 月 2 日的编辑:应通过应用 Android 团队提供的代码来解决错误:https ://stackoverflow.com/a/35132144/3397345 ,请参阅下面接受的答案。
27/01/2016 编辑:在 v23.1.1 中仍未解决错误。到目前为止提供的解决方案不提供透明状态栏(这是此布局的目的)或过于复杂。此处提供了该错误的新屏幕记录:https ://www.youtube.com/watch?v=76IxhlUx8MQ
23/07/2015 编辑:支持设计库 v22.2.1 未修复 :-( 这也发生在 MainActivity 的工具栏快速返回上!
28/07/2015 编辑:链接问题:CoordinatorLayout 状态栏填充在片段事务期间消失
从示例存储库https://github.com/chrisbanes/cheesesquare我已经在 Detail Activity 上实现了 ViewPager。它可以工作,但状态栏从第二页消失,正如您在图片中看到的那样,仅在棒棒糖设备中,知道吗?我使用android:fitsSystemWindows="true"
但它只在第一页有效:-(
activity_detail_viewpager.xml 如果我放在这里适合SystemWindows,StatusBar 不再透明,但它可以工作(状态栏填充不会丢失)。但我希望它透明!
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="ifContentScrolls"/>
</android.support.design.widget.CoordinatorLayout>
activity_detail_fragment.xml
<CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
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="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/back_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<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"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/card_margin">
...
</android.support.v7.widget.CardView>
...
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:src="@drawable/ic_discuss"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|end"
app:borderWidth="0dp"/>
</android.support.design.widget.CoordinatorLayout>
样式.xml v21
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>