How to change separator color in NavigationView?

I am trying to use NavigationView to implement NavigationDrawer. I added a separator by setting the group id in the menu. However, I do not see the delimiter. I think this is because the color of the separator is the same as the background color. So I want to change the color of the separator. But I can’t change it. Can anybody help me?

In the screenshot, there seems to be room for a separator between History and Settings , but you cannot see it.

enter image description here

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?> <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_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:fitsSystemWindows="true" tools:context=".ui.MapActivity"> <LinearLayout android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/toolbar_actionbar" /> <!--main content--> </LinearLayout> <android.support.design.widget.NavigationView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/navdrawer_background" app:insetForeground="#4000" app:itemTextColor="@color/navdrawer_item_text_color" app:itemIconTint="@color/navdrawer_item_icon_tint" app:headerLayout="@layout/drawer_header" 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: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"/> <item android:id="@+id/navdrawer_item_favourite" android:icon="@drawable/ic_drawer_fav" android:title="@string/navdrawer_item_fav"/> <item android:id="@+id/navdrawer_item_history" android:icon="@drawable/ic_drawer_history" android:title="@string/navdrawer_item_history"/> </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"/> <item android:id="@+id/navdrawer_item_help" android:icon="@drawable/ic_drawer_help" android:title="@string/navdrawer_item_help"/> <item android:id="@+id/navdrawer_item_about" android:icon="@drawable/ic_drawer_about" android:title="@string/navdrawer_item_about"/> </group> </menu> 
+24
android navigation-drawer navigationview android-navigationview
Jun 09 '15 at 11:32
source share
5 answers

just apply the following line in style.xml

 <item name="android:listDivider">your_color</item> 

The following is only information for your knowledge ... If you have seen the design support library, they use the following layout for seapator NavigationView.

 <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 conclusion that I am changing color on holo_blue enter image description here

+63
Jun 09 '15 at 11:58
source share

Here is the best and easiest way to use the menu as

 <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> 

enter image description here

+18
Jul 14 '16 at 5:49
source share

yas you need to add an empty header as a separator.

as

 <group android:id="@+id/my_id"> <!-- Divider will appear above this item --> <item ... /> </group> 

original answer

+1
Sep 24 '15 at 6:44
source share

Perfeita resposta p>

enter image description here

 <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"/> 
+1
Aug 4 '16 at 18:58
source share
 <!-- 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.

+1
Nov 02 '16 at 8:38
source share



All Articles