0

I'm using navdrawer with support of android.support.design.widget.NavigationView

I'd like to add a separator between groups (or first of "settings", it's not a problem), but I cannot find a method in web. Thank you for your support

base_layout.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        >
        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"
            />
        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>

    </LinearLayout>
    <!--
        IF YOU NEED HEADER:
        app:headerLayout="@layout/drawer_header"
    -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:menu="@menu/drawer"
        />
</android.support.v4.widget.DrawerLayout>

drawer.xml

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

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/home"
            android:checked="false"
            android:icon="@drawable/ic_home_black_24dp"
            android:title="@string/list_home" />

        <item
            android:id="@+id/list_event"
            android:checked="false"
            android:icon="@drawable/ic_list_black_24dp"
            android:title="@string/list_event" />

    </group>

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/settings"
            android:checked="false"
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="@string/settings" />

    </group>

</menu>

I did try to add View to drawer.xml but without success (simply nothing appear as divider):

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

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/home"
            android:checked="false"
            android:icon="@drawable/ic_home_black_24dp"
            android:title="@string/list_home" />

        <item
            android:id="@+id/list_event"
            android:checked="false"
            android:icon="@drawable/ic_list_black_24dp"
            android:title="@string/list_event" />

    </group>

    <View
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:background="#000000"/>

    <group android:checkableBehavior="single">

        <View
            android:layout_width="fill_parent"
            android:layout_height="10dp"
            android:background="#000000"/>

        <item
            android:id="@+id/settings"
            android:checked="false"
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="@string/settings" />

    </group>




</menu>
sineverba
  • 5,059
  • 7
  • 39
  • 84

2 Answers2

2

You need to add different id's to your groups, like:

<group android:id="@+id/group1">

<group android:id="@+id/group2">

etc.


EDIT: About height, I'm not sure if it work, but you can try add this to your styles.xml and apply this style to your NavigationView using style="@style/MyNavigationView" or android:theme="@style/MyNavigationView":

<style name="MyNavigationView" parent="Widget.Design.NavigationView">
    <item name="android:dividerHeight">10dp</item>
</style>
Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
  • It works. Like you can see, I set height of 10 dp (only to test); in my layout now I see them (I think) 1dp. Where I need to style them? Thank you ;-) – sineverba Jul 05 '15 at 17:29
  • Check my edit; there is no parameter for divier, but this can work. Try it. – Damian Kozlak Jul 05 '15 at 17:55
-1

You can add horizontal separator by this

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#3D7E9C"/>

If you want to add vertical separator , use android:layout_width="1dp"

Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
Shahbaz
  • 73
  • 8