How to create ripple effect in simple layout

Set these properties on your layout (if your layout has the default white/light background): android:clickable=”true” android:focusable=”true” android:background=”?attr/selectableItemBackground” You don’t need a custom drawable in this case. However, if your layout has a black/dark background, you’d have to create your own ripple drawable like this one: <?xml version=”1.0″ encoding=”utf-8″?> <!– An white rectangle ripple. –> <ripple … Read more

how to create ripple effect for pre-lollipop

For lollipop(API>21) make file as btn_ripple_effect.xml in drawable-v21 and put below code <?xml version=”1.0″ encoding=”utf-8″?> <ripple xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:color=”?android:colorAccent” tools:targetApi=”lollipop”> <item android:drawable=”@color/cancel_btn_clr” /> <!– default –> <item android:id=”@android:id/mask”> <shape android:shape=”rectangle”> <solid android:color=”?android:colorAccent” /> </shape> </item> </ripple> For pre lollipop (API<21)make file as btn_ripple_effect.xml in drawable folder and put below code <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> … Read more

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

Add ripple effect to my button with button background color?

Here is another drawable xml for those who want to add all together gradient background, corner radius and ripple effect: <?xml version=”1.0″ encoding=”utf-8″?> <ripple xmlns:android=”http://schemas.android.com/apk/res/android” android:color=”@color/colorPrimaryDark”> <item android:id=”@android:id/mask”> <shape android:shape=”rectangle”> <solid android:color=”@color/colorPrimaryDark” /> <corners android:radius=”@dimen/button_radius_large” /> </shape> </item> <item android:id=”@android:id/background”> <shape android:shape=”rectangle”> <gradient android:angle=”90″ android:endColor=”@color/colorPrimaryLight” android:startColor=”@color/colorPrimary” android:type=”linear” /> <corners android:radius=”@dimen/button_radius_large” /> </shape> </item> </ripple> Add … Read more