Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the colour of my sub menu header when using a NavigationView - Android

I'm unable to change the colour of my sub menu header, please see the image below.

I can change the background of the NavigationView, the colour of the fonts and the colour of the icons but I can't find an answer on the sub menu header.

e.g.

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/white"
    app:itemBackground="@color/white"
    app:itemIconTint="@color/dark_green"
    app:itemTextColor="@color/dark_green"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawer" />

Here is my menu xml:

<group android:checkableBehavior="single">
    <item
        android:checked="true"
        android:icon="@drawable/ic_attachment"
        android:title="@string/nav_item_attachment" />
    <item
        android:icon="@drawable/ic_image"
        android:title="@string/nav_item_images" />
    <item
        android:icon="@drawable/ic_place"
        android:title="@string/nav_item_location" />
</group>

<item android:title="@string/nav_sub_menu">
    <menu>
        <item
            android:icon="@drawable/ic_emoticon"
            android:title="@string/nav_sub_menu_item01" />
        <item
            android:icon="@drawable/ic_emoticon"
            android:title="@string/nav_sub_menu_item02" />
    </menu>
</item>

Please advise. :-).

NavigationView Sub Menu problem

like image 619
Lara Ruffle Coles Avatar asked Oct 19 '22 22:10

Lara Ruffle Coles


1 Answers

Try this code to do something like the image below

<menu>
    <group android:checkableBehavior="single">


        <item
            android:checked="true"
            android:icon="@drawable/ic_attachment"
            android:title="@string/nav_item_attachment" />
        <item
            android:icon="@drawable/ic_image"
            android:title="@string/nav_item_images" />
        <item
            android:icon="@drawable/ic_place"
            android:title="@string/nav_item_location" />
    </group>
    <group android:checkableBehavior="single">
       <item android:title="@string/nav_sub_menu">
        <menu>
            <item
                android:icon="@drawable/ic_emoticon"
                android:title="@string/nav_sub_menu_item01" />
            <item
                android:icon="@drawable/ic_emoticon"
                android:title="@string/nav_sub_menu_item02" />
        </menu>
      </item>
    </group>



</menu>

enter image description here

The difference with your code is that the code is inside a <group>...</group>

like image 194
Jorge Casariego Avatar answered Oct 31 '22 18:10

Jorge Casariego