I\'m trying to use NavigationView to implement NavigationDrawer. I have added the separator by setting group id in menu. However I can\'t see the separator. I guess it is be
Create a style in your styles.xml. Enter your preferred color in the android:listDivider
<style name="NavigationView" parent="Base.Theme.AppCompat">
<item name="android:listDivider">@color/text_lightgray</item>
</style>
Reference the style as the theme of your navigation view:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="false"
android:theme="@style/NavigationView"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"
app:itemTextColor="@color/text_white"/>
Lastly, make sure that the groups inside your menu have unique ids. If your groups do not have the id attribute, this won't work!
<group android:checkableBehavior="single"
android:id="@+id/group1">
<item
android:id="@+id/item1"
android:title="@string/item1" />
</group>
<group android:checkableBehavior="single"
android:id="@+id/group2">
<item
android:id="@+id/item2"
android:title="@string/item2" />
</group>
just apply following line on style.xml
<item name="android:listDivider">your_color</item>
The below is just information for your knowledge ... If you have seen design support library .. they are using following layout for NavigationView seprator..
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
</FrameLayout>
here, you can see android:background="?android:attr/listDivider" .. So enjoy ... and here is my output that i change color to holo_blue
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/menu_text_color</item>
<item name="android:textColorSecondary">@color/menu_text_color</item>
</style>
textColorPrimary changes the color of the header.
Here is best and easy way while using menu as view
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:theme="@style/ThemeToolbar.NavigationView"
app:itemTextColor="@color/white"
app:itemIconTint="@color/white"
app:headerLayout="@layout/activity_home_nav_header"
app:menu="@menu/activity_home_drawer" />
ThemeToolbar.NavigatinoView
<style name="ThemeToolbar.NavigationView" >
<item name="android:listDivider">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
yas you have to add blank header as separator.
like
<group android:id="@+id/my_id">
<!-- Divider will appear above this item -->
<item ... />
</group>
original answer
Perfect answer:
<android.support.design.widget.NavigationView
android:id="@+id/activity_principal_nav_view"
android:layout_width="@dimen/size_230"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/black"
android:fitsSystemWindows="true"
app:insetForeground="@color/white"
app:menu="@menu/settings_menu"
app:itemTextColor="@color/white"
app:itemIconTint="@color/white"
app:headerLayout="@layout/settings_menu_header"
android:theme="@style/NavigationDrawerStyle"/>