I wonder if anyone is having problems when redefining the background of the items on a NavigationView with app:itemBackground"
? I get the behavior shown on the screenshot, no matter what item I press the last item shows the ripple instead.
Here is my drawer_menu.xml
:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single" android:id="@+id/first_group">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home"
android:title="@string/nav_home" />
</group>
<group android:id="@+id/second_group">
<item
android:id="@+id/nav_settings"
android:title="@string/nav_settings" />
<item
android:id="@+id/nav_about"
android:title="@string/nav_about" />
<item
android:id="@+id/nav_logout"
android:title="@string/nav_logout" />
</group>
</menu>
My my_ripple.xml
:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffff0000">
<item
android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
My NavigationView:
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:headerLayout="@layout/drawer_header"
app:itemBackground="@drawable/my_ripple"
app:itemIconTint="@color/drawer_item"
app:itemTextColor="@color/drawer_item"
app:menu="@menu/drawer_menu" />
Ripple drawables should be defined like this sample:
read more
https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html