API 21状态栏后面的工具栏 [英] Toolbar behind status bar with API 21

查看:82
本文介绍了API 21状态栏后面的工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有CoordinatorLayout的片段

I've a fragment with a CoordinatorLayout

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

When i run the app with API 19 the behavior is right : The toolbar is below the status bar and the FAB button of the main_activity go away :

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

But with the API 21 and + : The toolbar is behind the status bar and the FAB button of the main_activity don't go away :

布局文件:

<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文件

I've add a specify style-v21 xml file

<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>

我找不到并理解问题所在.

I'dont find and understand the problem.

推荐答案

android:fitsSystemWindows="false"添加到CoordinatorLayout

这篇关于API 21状态栏后面的工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆