How can I change separator color in NavigationView?
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
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>