Reputation: 317
I am trying to style my navigation drawer after the specs from google. But I am not able to get this red marked submenu:
This is my current menu structure. I got the divider by splitting it into some groups but I don't get the title for the submenu.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/first_group"
android:checkableBehavior="single">
<item
android:id="@+id/alle_termine"
android:checked="false"
android:icon="@drawable/ic_assessment_24dp"
android:title="Alle Termine" />
</group>
<group
android:id="@+id/second_group"
android:visible="false">
<item
android:title="GROUPS"
android:enabled="false"
android:checkable="false">
</item>
</group>
</menu>
Is there a solution in xml or could it be done programmatically ? Both would be fine.
Upvotes: 1
Views: 1636
Reputation: 317
The answer from @kingdonnaz is working. But in my case i am editing the menu dynamically so my solution was to add the submenu in code :
SubMenu subMenu = menu.addSubMenu(R.id.second_group, 1, 0, "Submenutitel");
subMenu.add(R.id.second_group, s, 1, "GROUP1").setIcon(R.drawabel.ic_test);
Upvotes: 0
Reputation: 111
You need an xml that resembles this:
<group android:id="@+id/some_group_id">
<item android:id="@+id/some_item_id"
android:title="Subheader">
<menu>
<item
android:id="@+id/item_id_1"
android:icon="@drawable/mail"
android:title="@string/all_mail" />
<item
android:id="@+id/item_id_2"
android:icon="@drawable/trash"
android:title="@string/trash" />
<item
android:id="@+id/item_id_3"
android:icon="@drawable/spam"
android:title="@string/spam" />
</menu>
</item>
</group>
Create a group and add an item to it. The title of the item is what determines the title of the sub header like you want. Then you can add a regular menu with items to the sub header item.
Upvotes: 2