仅在support.v7.Toolbar下显示NavDrawer Scrim

时间:2014-10-21 20:00:53

标签: android android-support-library android-5.0-lollipop material-design

如果您查看Google Play商店应用,他们会启用网页布局(当您打开抽屉时会覆盖黑暗。除此之外,他们会在操作栏上显示稀松布,但不会使导航抽屉图标变暗或标题。是否有一种简单的方法可以达到这种效果?

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MyActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/my_awesome_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"/>


</LinearLayout>

<fragment android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/actionBarSize"
    android:layout_gravity="start|left"
    android:fitsSystemWindows="true"
    android:name="com.jawnnypoo.material.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer" />


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

正常 Normal

了解它们是如何仅仅修改动作栏,图标和文字不变 Only scrimming parts of the actionbar, not all

对我来说是什么样子 What it looks like for me

1 个答案:

答案 0 :(得分:2)

我不确定它是否是正确的解决方案,但我这样做了:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- Toolbar -->

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

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- content -->
        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <fragment
            android:id="@+id/navigation_drawer"
            android:name="com.jawnnypoo.material.NavigationDrawerFragment"
            android:layout_width="@dimen/navigation_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start|left" />

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