Android NavigationView menu group divider

Shaddow picture Shaddow · Jun 18, 2015 · Viewed 50.4k times · Source

Android support design library provide NavigationView:

 <android.support.design.widget.NavigationView
    ...
    app:menu="@menu/navigation_drawer_items" />

menu/navigation_drawer_items:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item .../>
        ...
    </group>

    <group android:checkableBehavior="single">
        <item .../>
        ...
    </group>

</menu>

How to add divider, separator or space between groups (like on picture)?

enter image description here

Answer

Moinkhan picture Moinkhan · Jun 18, 2015

Just give a unique id to each group. It will create a separator automatically.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:id="@+id/group_feature"
        android:checkableBehavior="single">
        <item android:id="@+id/navdrawer_item_map"
            android:checked="true"
            android:icon="@drawable/ic_drawer_map"
            android:title="@string/navdrawer_item_map"/>

    </group>
    <group android:id="@+id/group_settings"
        android:checkableBehavior="single">
        <item android:id="@+id/navdrawer_item_settings"
            android:icon="@drawable/ic_drawer_settings"
            android:title="@string/navdrawer_item_settings"/>

    </group>
</menu>