使导航抽屉绘制在状态栏后面 [英] Make navigation drawer draw behind status bar

查看:28
本文介绍了使导航抽屉绘制在状态栏后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个类似于 Material 规范中的 Nav Drawer(就像新的 gmail 应用程序中的那个).注意导航抽屉的内容是如何绘制在状态栏后面的:

使用来自

I'm trying to create a Nav Drawer like the one from the Material spec (like the one from the new gmail app). Note how the contents of the nav drawer draw behind the status bar:

Using Chris Banes' answer from this question, I was able to successfully make the navigation drawer in my app draw behind the status bar; that's working fine. What isn't working is drawing the contents of the nav drawer behind the status bar. I want the blue image in my drawer to be displayed behind the status bar, but that area is drawn with the color of status bar, as seen in this screenshot.

So, how can I make my navigation drawer draw in the area behind the status bar? I've posted the relevant parts of my project below.

Base layout containing the navigation drawer:

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

    <!-- Framelayout to display Fragments -->
    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/warning_container" />

    <FrameLayout
        android:id="@+id/navigation_drawer_fragment_container"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:layout_gravity="start">

        <fragment
            android:id="@+id/navigation_drawer_fragment"
            android:name="com.thebluealliance.androidclient.fragments.NavigationDrawerFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:layout="@layout/fragment_navigation_drawer" />

    </FrameLayout>

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

Theme of my activity

<style name="AppThemeNoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

In onCreate() of my activity, I do the following:

mDrawerLayout.setStatusBarBackground(R.color.primary_dark);

解决方案

I found the best way to do this on Android 5.0. The key is to use a ScrimInsetFrameLayout as the root element of the navigation drawer (the second View in the DrawerLayout). This will make the content expand to fill the space behind the status bar. To color the inset properly, you can set the following attribute on the ScrimInsetFrameLayout:

app:insetForeground="#4000"

Also, make sure that you have android:fitsSystemWindows="true" on the scrim layout!

The source code for the ScrimInsetFrameLayout can be found here: https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/ScrimInsetsFrameLayout.java

这篇关于使导航抽屉绘制在状态栏后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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