Search code examples
androidnavigation-drawerandroid-navigationview

Change NavigationView divider color and sub header text color


I im using the android studio navigationview.
But i change the navigationview color background to black,
and the divider for subheader gone(because the divider is also black).
Also the subheader title is gone.

Is there a way to change those properties to white or any color?
Here is my XML for my menu.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group
        android:id="@+id/nav_header"
        android:checkableBehavior="single">
        <item
            android:id="@+id/nav_home"
            android:checked="true"
            android:icon="@drawable/ic_home_black_24dp"
            android:title="Home" />
        <item
            android:id="@+id/nav_search"
            android:icon="@drawable/ic_search_black"
            android:title="Search Location" />
        <item
            android:id="@+id/nav_fav"
            android:icon="@drawable/ic_favorite"
            android:title="Favorites" />
        <item
            android:id="@+id/nav_recent"
            android:icon="@drawable/ic_nav_route"
            android:title="Recent Location" />
        <item
            android:id="@+id/nav_route"
            android:icon="@drawable/ic_place"
            android:title="Route" />
    </group>


    <item
        android:id="@+id/navigation_subheader"
        android:title="Others">
        <menu>
            <item
                android:id="@+id/nav_settings"
                android:checkable="true"
                android:icon="@drawable/ic_settings"
                android:title="Settings" />
            <item
                android:checkable="true"
                android:id="@+id/nav_about"
                android:icon="@android:drawable/ic_menu_send"
                android:title="About" />
        </menu>
    </item>

</menu>

Thanks!


Solution

  • For the separator you need to add style to your theme or NavigationView theme and change the value of android:attr/listDivider. Thats the background that divider is using.

    Subheader is just a TextView. When you change the color of the divider you will see that it changes to the subheader. To change subheader text change the android:textColorPrimary and android:textColorSecondary in v21 value in your style too.