I am attempting to replace what I thought was the default item background of the NavigationView
. So I created a drawable to replace the background and applied it using the itemBackground
attribute.
background_navigation_view_item.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/navigation_item_background_tint">
<item android:id="@android:id/mask" android:top="4dp" android:bottom="4dp" android:left="8dp" android:right="8dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="3dp"/>
</shape>
</item>
<item android:top="4dp" android:bottom="4dp" android:left="8dp" android:right="8dp">
<selector>
<item android:state_checked="true">
<shape android:shape="rectangle">
<solid android:color="@color/navigation_item_background_tint"/>
<corners android:radius="3dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<corners android:radius="3dp"/>
</shape>
</item>
</selector>
</item>
</ripple>
The item background drawable looks great when the item is selected ("Selection Controls" is the selected item in the image below). But when the item is being clicked ("Progress Indicators" below) it appears that both the default ripple drawable and the background_navigation_view_item.xml
drawable are being used (only a rounded rectangle should be shown, not the rectangle surrounding it).
I also tested the drawable as the background of a checkable view, and it works the way I would expect. So if it isn't an error in the code for my drawable, why isn't the original background drawable being replaced?