I'm following this color scheme of Navigation View.
I created 3 selectors, for background, text and icon. When I set the selectors, my navigation view looked like this:
The problem is that no item is shown selected and if I press one item, all items' background color changes to gray. Icon never gets the primary color.
Here is are the XMLs:
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:itemTextColor="@drawable/nav_item_text"
app:itemIconTint="@drawable/nav_item_icon_tint"
app:itemBackground="@drawable/nav_item_background"
app:headerLayout="@layout/drawer_student_data_header"
app:menu="@menu/drawer"
android:id="@+id/navigationView"/>
nav_item_icon_tint.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/gray_600"/>
<item android:state_selected="true" android:color="@color/primary" />
<item android:color="@color/gray_600" />
</selector>
nav_item_text.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/black_87_percent"/>
<item android:state_selected="true" android:color="@color/primary" />
<item android:color="@color/black_87_percent" />
</selector>
nav_item_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/gray_400"/>
<item android:state_selected="true" android:drawable="@color/gray_200" />
<item android:drawable="@android:color/white" />
</selector>