I have a standard Navigation Drawer, pre-created by Android Studio and want to populate it with number of groups. I started with this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_mode_person"
android:icon="@drawable/ic_person_black_24dp"
android:title="Person" />
<item
android:id="@+id/nav_mode_group"
android:icon="@drawable/ic_group_black_24dp"
android:title="Community" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_menu_share"
android:title="Share" />
<item
android:id="@+id/nav_send"
android:icon="@drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>
</menu>
But what I didn't get is if it even possible to give each group a title? I mean there is an android:title
option available for <item>
s, but it is unavailable for <group>
s and if I try to wrap groups around items, what I get is a messy entries behavior.
I read through Google's design guideline on Navigation Drawer, but missed the point if groups should have its own names or they should not. Here is a picture of what I want to achieve:
Is it possible without adding random <TextView>
s? By the way, I want to do it via XML, not programmatically.
You also required to have an outer group with
android:checkableBehavior="single"
so that no two item is selected one fromFirst Category
and other fromSecond Category
. Here is the working code.Here is well defined how to create menus.
http://developer.android.com/guide/topics/ui/menus.html
So in your case create your list in this order item->menu->group. that is to say:
add xml class
navigation_drawer_title
:and change your
navigationAdapter
like thisand
You are right, it's not possible to give groups a title. The only option seems to be to wrap groups into
<item>
and<menu>
tags like thisResulting in a navigation drawer menu like this