其他分享
首页 > 其他分享> > Android DrawerLayout(带有NavigationView)状态栏后面

Android DrawerLayout(带有NavigationView)状态栏后面

作者:互联网

我有一个带有DrawerLayout的应用程序,其中包含NavigationView:

activity_layout.xml:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    android:fitsSystemWindows="true">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/activity_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.exmaple.appname.activityname">

        <android.support.v7.widget.Toolbar
            android:id="@+id/actionbar_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/Theme.AppCompat"/>

        […]

    </android.support.constraint.ConstraintLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/nav_drawer"
        android:fitsSystemWindows="true"/>

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

我还添加了以下样式:

styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    […]

    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style>

值-21 / styles.xml:

<style name="AppTheme.NoActionBar" parent="AppTheme">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

所有这些代码都基于Google I/O Schedule App,但DrawerLayout仍然不会在状态栏后面呈现.关于为什么这种解决方案组合不起作用以及可能有哪些解决方案的任何想法?我发现在状态栏后面绘制从来都不是一个通用的解决方案,但在尝试了Stack Overflow上的每个解决方案组合后,我都能想到,我仍然无法得到它.

当前抽屉图像:
enter image description here

解决方法:

只需添加< item name =“android:windowTranslucentStatus”> true< / item>在values-21 / styles.xml中删除此< item name =“android:statusBarColor”> @android:color / transparent< / item>

将android:fitsSystemWindows =“true”添加到xml中的NavigationView

Working example!

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

结果enter image description here

Edited (main layout)

<?xml version="1.0" encoding="utf-8"?>
<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" <--This is mandatory 
    tools:context=".ui.activities.MainActivity">

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white" />

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="true" /><--This is mandatory 

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

Current Result 07001

Update: I lookup your style-v21 and found below

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme.NoActionBar" parent="AppTheme">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>

请用它替换它

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

标签:drawerlayout,android-statusbar,navigationview,android
来源: https://codeday.me/bug/20191008/1874271.html