android:windowLightStatusBar和导航抽屉之间的问题

3
我已将android:windowLightStatusBar设置为true,以在我的应用程序中显示黑色图标和状态栏内的文本,如下图所示。

enter image description here

然而,导航抽屉不再适合屏幕大小,如下图所示。这是因为要确保android:windowLightStatusBar生效,必须将android:windowTranslucentStatus设置为false。有什么解决办法吗?像Google日历这样的应用程序似乎可以很好地使用此功能。

enter image description here

这是我的主活动XML

<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_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorToolbarBackground"
    android:fitsSystemWindows="true"
  >

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

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

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>


    <android.support.design.widget.NavigationView

        android:id="@+id/navigation_view"
        android:background="@color/colorWhite"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"

        app:menu="@menu/navigation_view_items" />

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

1
您是否想让NavigationDrawer重叠状态栏? - Michele Lacorte
是的,就像谷歌日历。 - cw fei
请添加您的layout.xml文件。 - Michele Lacorte
我添加了XML。 - cw fei
1个回答

1
layout.xml 中删除此行。
android:fitsSystemWindows="true"

将以下内容添加到 styles-v21.xml 文件中。

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

styles.xml 中。
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

在 Manifest.xml 文件中,在你的 Activity Main 中添加以下内容。
android:theme="@style/AppTheme.NoActionBar"

AppBarLayout 标签包含在此中:
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <!-- Here AppBarLayout ecc -->

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

<!-- Here NavigationView ecc -->

AppBarLayout必须有

android:theme="@style/AppTheme.AppBarOverlay"

现在它可以工作了,你真是个天才,能解释一下为什么用CoordinatorLayout包装它会让它工作吗? - cw fei
CoordinatorLayout 用于与一个或多个子视图进行特定交互,可以在这里查看 CoordinatorLayout - Michele Lacorte

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接