5

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

Lara Ruffle Coles
  • 293
  • 1
  • 2
  • 15

2 Answers2

2

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>

Jorge Casariego
  • 21,948
  • 6
  • 90
  • 97
  • Hi Jorge, please see above. – Lara Ruffle Coles Nov 10 '15 at 17:35
  • @LaraRuffleColes have you added ... outside all the code? Something like this ... – Jorge Casariego Nov 10 '15 at 17:40
  • Yep, sorry for forgetting to paste that in. Here is my GitHub: https://github.com/lararufflecoles/TutorialStartScreenAndSideMenu/blob/master/app/src/main/res/menu/drawer.xml But don't worry too much about responding, discussed it with the other half last night and he said the sub menu hasn't really been designed to allow for proper amendments, and that isn't something you ever really mess with. I just wanted to mess with it! I'm going to give up.... – Lara Ruffle Coles Nov 11 '15 at 10:28
1

@Jorge

Like this?

<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>

It doesn't seem to make a difference

Lara Ruffle Coles
  • 293
  • 1
  • 2
  • 15