How to change duration of ripple effect in Android?

5k Views Asked by At

I have implemented a ripple effect in android. Using the following code:-

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ff00ff00">
    <item android:drawable="@android:color/black" />
</ripple>

And set it to the background of a textview

android:background="@drawable/ripple_over_drawable"

But the problem is that the ripple animation is very fast. I want to slow it down.

3

There are 3 best solutions below

1
On

Use below code for ripple effect;

ripple_over_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><shape>
    <stroke android:width="1dp" android:color="#FFF" />

    <solid android:color="@color/color" />

    <corners
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />
</shape></item>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ffff0000" />
</selector>
0
On

I have used this Library called as RippleEffect.

Its very easy to use and provides bunch of modification and customization.

app:rv_rippleDuration [integer def:400] --> Duration of the ripple animation

You can play around with various options.

1
On

You can achieve the same effect by setting this as a background to the view:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:enterFadeDuration="400"
    android:exitFadeDuration="500">
    <item
        android:state_pressed="true">
        <shape>
            <solid android:color="@color/chrome_grey" />
        </shape>
    </item>
    <item>
        <shape>
            <solid android:color="@android:color/white"/>
        </shape>
    </item>
</selector>