19

I have a ripple working with a custom color. However, the color is never fully opaque. According to the answers from What should be the color of the Ripple, colorPrimary or colorAccent? (Material Design) it always has an alpha of 40%. Looking at the answers I've tried to use the following v21 specific drawable xml to force an opaque red background once selected:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="#ffff0000">
    <item android:id="@android:id/mask">
        <color android:color="#ffffffff" />
    </item>
</ripple>

However, I always get an alpha red, not an opaque red as I want. Is it possible to get an opaque ripple? Here is a screenshot of the ripple, where the red is never fully opaque.

enter image description here

You can find a simple example of the ripple effect at https://github.com/gradha/Stackoverflow33217896 using an XML ripple and another one generated by code. The latter suggests it is not possible to implement an opaque ripple without rewriting the code.

Community
  • 1
  • 1
Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78
  • 8
    As you can see [in source of `RippleDrawable`](https://github.com/android/platform_frameworks_base/blob/master/graphics/java/android/graphics/drawable/RippleDrawable.java#L865), `halfAlpha` is computed and applied to the `Paint` object. And that is not configurable, meaning no `if-else` statement to change that with styles or programatically. – azizbekian Apr 11 '17 at 16:07
  • https://android.jlelse.eu/the-missing-custom-ripple-effect-library-834521721b41 – mudit_sen Jul 25 '18 at 13:11
  • have you got any solution? – zihadrizkyef Feb 08 '21 at 08:25

1 Answers1

1

You can simply put alpha value for bounded ripple.

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?android:attr/colorAccent">
    <item android:id="@android:id/mask">
        <color android:color="#42ffffff" />
    </item>
</ripple>

for unbounded ripple You can set opacity from color if you know your accent color

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/accent_26" />

colors.xml

<resources>
    ...
    <color name="accent">#ff33b5e5</color>
    <color name="accent_alpha26">#4233b5e5</color>
</resources>
Lalit Jadav
  • 1,409
  • 1
  • 15
  • 38