0

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?

  • On tap (click and let go), show regular on press color, no ripple.
  • When holding the finger longer - show ripple
  • Start fade out after 6 milliseconds after the on press

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?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • Did you see [rippleEffect](https://github.com/traex/RippleEffect) library before? it may help you – kAvEh Jun 25 '19 at 10:40

1 Answers1

0

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" />

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60