Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation drawer menu sub categories

I have a Navigation Drawer in my app using the DrawerLayout class and NavigationView. Right now I have my drawer showing all of my categories by inflating a menu xml file. How can I get it so that some of these categories are separated by subheadings and dividers?

like image 650
Darren Mao Avatar asked Jul 08 '15 15:07

Darren Mao


People also ask

What is the drawer menu?

The navigation drawer is a UI panel that shows your app's main navigation menu. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen.

How do you use a navigation drawer?

The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar. The drawer icon is displayed on all top-level destinations that use a DrawerLayout.

What is drawer layout in Android?

DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.


1 Answers

You can do this very easily by just modifying your existing menu xml file.

Your code will look something like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/group1"
        android:title="title1">
        <menu>
            <item
                android:title="item1" />
            <item
                android:title="item2" />
        </menu>
    </item>

    <item
        android:id="@+id/group2"
        android:title="title2">
        <menu>
            <item
                android:title="item1" />
            <item
                android:title="item2" />
            <item
                android:title="item3" />
        </menu>
    </item>
</menu>

All you do is specify a new menu within each item and give the parent item a title!

like image 51
adao7000 Avatar answered Sep 22 '22 13:09

adao7000