【问题标题】:Toolbar behind status bar with API 21带有 API 21 的状态栏后面的工具栏
【发布时间】:2016-11-23 21:56:17
【问题描述】:

我有一个带有 CoordinatorLayout 的片段

当我使用 API 19 运行应用程序时,行为是正确的: 工具栏位于状态栏下方,main_activity 的 FAB 按钮消失:

但是使用 API 21 和 + : 工具栏位于状态栏后面,main_activity 的 FAB 按钮不会消失:

布局文件:

<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/caves_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/caves_appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/detail_backdrop_height"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/caves_collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimaryDark"
            app:expandedTitleMarginStart="78dp"
            app:expandedTitleMarginEnd="124dp">

            <ImageView
                android:id="@+id/caves_backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:background="@drawable/drawer_header_bg"
                app:layout_collapseMode="parallax"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_horizontal">

            </LinearLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/caves_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.v7.widget.RecyclerView
        android:id="@+id/caves_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/caves_fab"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_anchor="@id/caves_appbar"
        app:layout_anchorGravity="bottom|right|end"
        android:src="@drawable/ic_discuss"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"/>

</android.support.design.widget.CoordinatorLayout>

我添加了一个指定 style-v21 xml 文件

<resources>
    <style name="AppTheme" parent="Base.Theme.Design">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowSharedElementsUseOverlay">false</item>
    </style>
</resources>

我没有发现和理解问题。

【问题讨论】:

  • Activity 的行为是正确的,但对于 API 21 的 Fragment 则不正确。

标签: android android-layout


【解决方案1】:

android:fitsSystemWindows="false"添加到CoordinatorLayout

【讨论】:

  • 这个bug修复得很好!
  • 你太棒了!为我节省了更多时间的挫败感。这应该是公认的答案。
【解决方案2】:

遇到了类似的问题(例如here

我的工作方式是将android:fitsSystemWindows="false" 添加到AppBarLayout 并在true 上添加CoordinatorLayout

【讨论】:

  • 为我工作,我有
【解决方案3】:

去掉这条线:

<item name="android:windowTranslucentStatus">true</item>

【讨论】:

  • 谢谢,但不起作用。这种行为只是当我使用片段和 API 21 和 +
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多