Shaddow Shaddow - 4 months ago 132
Android Question

Android NavigationView menu group divider

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

Just give the unique id to each group. It will create s 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>