状态栏后面的工具栏,带有API 21

Sel*_*bis 6 android android-layout

我有一个带有CoordinatorLayout的片段

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

Api19

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

布局文件:

<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>
Run Code Online (Sandbox Code Playgroud)

我添加了一个指定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>
Run Code Online (Sandbox Code Playgroud)

我找不到并理解这个问题.

小智 22

添加android:fitsSystemWindows="false"CoordinatorLayout


Mat*_*yas 6

有类似的问题(这里举例说明)

我如何使它的工作是增加android:fitsSystemWindows="false"AppBarLayout,并有它trueCoordinatorLayout


Moh*_*uag 2

去掉这条线:

<item name="android:windowTranslucentStatus">true</item>
Run Code Online (Sandbox Code Playgroud)