I write an android code that has ripple effect by adding:
android:background="?attr/selectableItemBackground"
I need to tweak it. I know how to change the ripple color. But do you think the following are even possible to tune?
I know adding a drawable selector allows to control more states, but I don't think it can control duration.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="@color/grey200_alpha_10"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="oval">
<solid android:color="@color/grey200_alpha_12"/>
</shape>
</item>
<item android:state_hovered="true">
<shape android:shape="oval">
<solid android:color="@color/grey200_alpha_4"/>
</shape>
</item>
</selector>
Is it possible?
If you wish to proceed with github library then this can help you
https://github.com/traex/RippleEffect
It has a property called app:rv_rippleDuration
which lets you control the duration. Also it has many other properties. Must try it out
EDIT
Here is a nice answer given by Sunny on StackOverflow
Under the /platforms/android-14/data/res/themes.xml
you can find the sources that @android:integer/config_mediumAnimTime
is used for the duration you want to tweak.
Now, you can create your own custom drawable file and change the time as per your requirement.
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_window_focused="false" android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true" android:drawable="@drawable/list_selector_background_focused" />
<item android:drawable="@color/transparent" />