How to achieve Ripple effect? It can be achieved in 2 ways : a Programmatically — by using RippleDrawable class. In order to understand how the ripple is drawn it would be nice to slow the animation down.
Programmatically Our respective class will implement View. OnTouchListener interface. It will provide us : public abstract boolean onTouch View v, MotionEvent event callback.
This is called, when a touch event is dispatched to a view. Here, v : The view, the touch event has been dispatched to.
This method returns True if the listener has consumed the event, False otherwise. The ripple android position of the ripple for a given state is specified by calling setHotspot float, float with the corresponding state attribute identifier.
And then, we set our required color to the rippledrawable object. If you want to apply the standard ripple effect on Android 5.
It will be bounded by the nearest parent of the view with a ripple android background. This drawable may contain 0 or more child layers, including a special mask layer that is not drawn to the screen.
Attributes are as under : android:color — the color to use for ripple effects. Here, background color of button is changed by setting the child layer in the Ripple drawable XML.