【问题标题】:Status bar turns white when using custom Toolbar使用自定义工具栏时状态栏变为白色
【发布时间】:2016-07-19 15:50:32
【问题描述】:

我正在使用带有工具栏的 NavigationView。状态栏的背景是白色的。如果您有任何问题,请在投票前发表评论,我会尽快查看。

activity_main.xml

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

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

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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

<android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer/>
    </android.support.v4.widget.DrawerLayout>

app_bar_main.xml

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="?attr/colorPrimaryDark">
</android.support.v7.widget.Toolbar>

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

colors.xml

<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>

【问题讨论】:

  • 尝试类似:android:fitsSystemWindows="false"
  • 你是如何定义@color/colorPrimaryDark(在colors.xml中)的?
  • 上传你的 color.xml 文件
  • @GuilhermeP 请查看我在帖子上的最新编辑
  • @ArbenMaloku 我试过了,结果没有改变

标签: java android toolbar statusbar navigationview


【解决方案1】:

您必须在父级 (DrawerLayout) 中添加此属性 android:fitsSystemWindows="true"。修复使用时的白色状态栏。

要了解更多信息,请参阅此链接Why would I want to fitsSystemWindows?

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

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

    <include
        android:id="@+id/toolbar"
        layout="@layout/tool_bar" />

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

</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_header"
    app:itemTextColor="@color/primary_dark"
    app:menu="@menu/my_navigation_items" />

【讨论】:

  • 哇,就这么简单吗?非常感谢。
猜你喜欢
  • 1970-01-01
  • 2014-11-26
  • 1970-01-01
  • 2018-04-11
  • 1970-01-01
  • 1970-01-01
  • 2015-02-28
  • 1970-01-01
  • 2021-09-19
相关资源
最近更新 更多