Android ripple background color
It's a lot easier to do with styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> ... <item name="colorControlHighlight">@color/ripple_material_dark</item> ...</style>
You can control the colour of the RippleDrawable
by doing the following:
RippleDrawable rippleDrawable = (RippleDrawable)view.getBackground(); // assumes bg is a RippleDrawableint[][] states = new int[][] { new int[] { android.R.attr.state_enabled} };int[] colors = new int[] { Color.BLUE }; // sets the ripple color to blueColorStateList colorStateList = new ColorStateList(states, colors);rippleDrawable.setColor(colorStateList);
Or, via XML:
<?xml version="1.0" encoding="utf-8"?><ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="#FFFF0000"> <!-- The ripple will be red --> <!-- the normal bg color will be light grey --> <item> <color android:color="#FFDDDDDD" /> </item> <!-- make sure the ripple doesn't exceed the bounds --> <item android:id="@android:id/mask"> <shape android:shape="rectangle"> <solid android:color="?android:colorAccent" /> </shape> </item></ripple>
EDIT
After seeing @i.shadrin's answer below, I must admit it's a much simpler approach (using styles). If this is an option for you, I would recommend it.
add these two line of code inside of your view to give ripple effect .
android:clickable="true"android:background="?attr/selectableItemBackground"