How to use RippleDrawable programmatically in code (not xml) with Android 5.0 Lollipop?

This is how I was able to achieve this. Note that this is Api 21+ only so you will have to fallback to a normal Drawable if you support lower versions. public static RippleDrawable getPressedColorRippleDrawable(int normalColor, int pressedColor) { return new RippleDrawable(getPressedColorSelector(normalColor, pressedColor), getColorDrawableFromColor(normalColor), null); } public static ColorStateList getPressedColorSelector(int normalColor, int pressedColor) { return … Read more

Lollipop RippleDrawable vs Selector for Pre-Lollipop

1) Yes. See the documentation for RippleDrawable for more details on how layers are composited, but basically you want: <?xml version=”1.0″ encoding=”utf-8″?> <ripple xmlns:android=”http://schemas.android.com/apk/res/android” android:color=”?android:attr/colorControlHighlight”> <item android:drawable=”https://stackoverflow.com/questions/24607339/@drawable/yourninepatch” /> </ripple> Or to also handle the disabled state in a clean way, you might want: <?xml version=”1.0″ encoding=”utf-8″?> <ripple xmlns:android=”http://schemas.android.com/apk/res/android” android:color=”?android:attr/colorControlHighlight”> <item> <selector> <item android:state_enabled=”false”> <nine-patch android:src=”https://stackoverflow.com/questions/24607339/@drawable/yourninepatch” … Read more

Ripples on a shape with a transparent background

After a few trial and errors it seems I have misunderstood the hierarchy of the selector and item. The following works perfectly. <ripple xmlns:android=”http://schemas.android.com/apk/res/android” android:color=”@color/primary_light”> <item android:id=”@android:id/mask”> <shape android:shape=”oval”> <solid android:color=”@android:color/white”/> <size android:height=”80dp” android:width=”80dp”/> </shape> </item> </ripple>

Android L’s Ripple Effect – Touch Feedback for Buttons – Using XML

UPDATE Material Components: With the Material Components Library it is very easy to apply a ripple. Just use the MaterialButton and the app:rippleColor attribute: <com.google.android.material.button.MaterialButton app:rippleColor=”@color/my_selector” ../> With a selector like this: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:alpha=”…” android:color=”?attr/colorOnPrimary” android:state_pressed=”true”/> <item android:alpha=”…” android:color=”?attr/colorOnPrimary” android:state_focused=”true” android:state_hovered=”true”/> <item android:alpha=”…” android:color=”?attr/colorOnPrimary” android:state_focused=”true”/> <item android:alpha=”…” android:color=”?attr/colorOnPrimary” android:state_hovered=”true”/> <item android:alpha=”…” android:color=”?attr/colorOnPrimary”/> </selector> … Read more

Listview selector with colored background and ripple effect

I’ve managed to get individually colored list items while maintaining the ripple effect. Set the background of your list items using whatever adapter you have and set the listview to show the selector on top: <ListView android:layout_width=”match_parent” android:layout_height=”match_parent” android:drawSelectorOnTop=”true” /> This will draw the ripple effect above the background.

How to set state_selected in ripple drawable

Found the answer, just in case someone else having the same problem <?xml version=”1.0″ encoding=”utf-8″?> <ripple xmlns:android=”http://schemas.android.com/apk/res/android” android:color=”#DDDDDD” > <item> <selector> <item android:state_selected=”true”> <color android:color=”#EEEEEE” /> </item> <item android:state_activated=”true”> <color android:color=”#EEEEEE” /> </item> <item> <color android:color=”#FFFFFF” /> </item> </selector> </item> </ripple>