I am trying to create a drawable that ripples when pressed, but when view.setSelected(true) is called, it contains a solid background color.
The following file is placed in the drawable-v21 folder:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true"> <color android:color="@color/green_primary" /> </item> <item android:state_pressed="true"> <ripple android:color="@color/green_primary"> <item android:id="@android:id/mask"> <shape android:shape="rectangle"> <solid android:color="@color/green_selected" /> </shape> </item> </ripple> </item> </selector>
I tried above and it has a solid background when it is selected, but the ripple effect is not, but rather a kind of damping effect. If I only have ripple without a selector, it pulses correctly when pressed, but obviously then I have no selected state. How could I bake in the same background?
source share