Subcategory Navigation Box Menu

I have a navigation box in my application using the DrawerLayout and NavigationView class. Right now I have my mailbox showing all my categories, inflating an XML menu file. How can I get it so that some of these categories are separated by subtitles and separators?

+6
source share
2 answers

You can do this very easily by simply modifying the existing xml menu 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 inside each element and provide the parent element with a title!

+5
source

I think this code will help you set up a separator between your items and items. Check this:

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> <group android:id="@+id/grp1" android:checkableBehavior="single" > <item android:id="@+id/navigation_item_1" android:checked="true" android:icon="@drawable/ic_home" android:title="@string/navigation_item_1" /> </group> <group android:id="@+id/grp2" android:checkableBehavior="single" > <item android:id="@+id/navigation_item_2" android:icon="@drawable/ic_home" android:title="@string/navigation_item_2" /> </group> 

Happy coding

0
source

All Articles