Navigation Drawer item background colour for selected item
To solve this problem:
1- You don't need android:listSelector under your ListView.
2- Open (or Create) styles.xml under (res/values).
<!-- Base application theme. --><style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="android:activatedBackgroundIndicator">@drawable/drawer_list_selector</item></style>
3- Under res/drawable folder create drawer_list_selector.xml file
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/light_gray_color" /> <item android:state_activated="true" android:drawable="@drawable/red_color" /> <item android:drawable="@android:color/transparent" /></selector>
4- Under res/drawable create red_color.xml / light_gray_color.xml (or any other name) and add your desired Hex color:
<?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#C8FF0000"/></shape>
5- Open your project AndroidManifest.xml and add android:theme tag (if not exist)
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
Reference / Credit: Changing Navigation Drawer Selected Item Color from default blue
To change the "Navigation Drawer item background colour for selected item" you could do it with the attribut:
colorControlHighlight
In your "styles.xml" it could look like this:
<style name="YourStyleNameFor.NavigationDrawer" parent="ThemeOverlay.AppCompat.Light"> <item name="colorControlHighlight">@color/your_highlight_color</item></style>
Don't forget to apply your Style in the tag:
android.support.design.widget.NavigationView
For example in your activity_main.xml it could look like this:
<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" app:headerLayout="@layout/navigationdrawer_header" <!-- the following line referes to your style --> app:theme="@style/YourThemeNameFor.NavigationDrawer" <!-- the following two lines are maybe also interesting for you --> app:itemIconTint="@color/gray3" app:itemTextColor="@color/gray3" app:menu="@menu/navigationdrawer_main" />
This is working for me:
First define a drawable
item_bg.xml
as:<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/nav_menu_bg" /> </selector>
Then use this drawable in
navigation_main_layout.xml
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" app:itemBackground="@drawable/item_bg" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_navigation" app:menu="@menu/navigation_main_layout_drawer" />