使用 DrawerLayout 和 Collapsing ToolbarLayout 不能有透明状态栏

Cannot have a Transparent Status Bar using DrawerLayout and Collapsing ToolbarLayout

首先,我对抽屉不在状态栏和此类问题没有任何问题。那工作正常。

其次,我们有一个很好的选择,即使用 Collapsing Toolbar 显示透明的状态栏,并在其后面显示图像。例如 -

这里可以看到状态栏是透明的

现在如果我使用 DrawerLayout 而不是 Cordinator 一个,(其中 Coordinator 是 DrawerLayout 的直接子级)我得到这个结果 -

这是我的代码片段 -

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".Dashboard">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="32dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">


                <ImageView
                    android:id="@+id/toolbarImage"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:alpha="0.7"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/morning_1"
                    app:layout_collapseMode="parallax" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@+id/activity_dashboard_greeting"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="40dp"
                        android:text="Good Morning !!"
                        android:textColor="@color/white"
                        android:textSize="28dp" />

                    <com.meg7.widget.CircleImageView
                        android:id="@+id/activity_dashboard_image"
                        android:layout_width="88dp"
                        android:layout_height="88dp"
                        android:layout_below="@+id/activity_dashboard_greeting"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="16dp"
                        android:src="@drawable/arrow_expense" />

                </RelativeLayout>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

        <include layout="@layout/content_dashboard" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_add"
            app:layout_anchor="@+id/appBar"
            app:layout_anchorGravity="bottom|right" />

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/menu_navigation">

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

</android.support.v4.widget.DrawerLayout>

请注意,即使第一张图片不同 activity 第二张图片也完全相同。

感谢您的宝贵时间。提前致谢。

也将 android:fitsSystemWindows="true" 添加到 CoordinatorLayout。