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?
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.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With