抽屉布局颜色不变

时间:2018-08-28 09:23:39

标签: android android-layout navigation-drawer

试图将导航抽屉的颜色更改为colorPrimary,但是即使将抽屉布局的颜色设置为colorPrimary也没有改变。它在Android Studio上显示,但在实际运行中设置为白色。!

<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:fitsSystemWindows="true"
android:padding="0dp"
android:paddingBottom="0dp"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:itemBackground="@color/colorPrimary" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@android:color/background_light"
    app:itemTextColor="@android:color/background_light"
    app:menu="@menu/activity_main_drawer">

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

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

选中此一个

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试此代码。

<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_drawer_header"
app:menu="@menu/menu_drawer"
android:background="@color/color_navigation_list_background"
app:itemIconTint="@color/color_selector_navigation_item"
app:itemTextColor="@color/color_selector_navigation_item"/>