20

In referring to the RippleDrawable for Android L, https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html, there's a way to mask away to contain the ripple effect within the view. The masking is done as

<ripple android:color="#ff0000ff">
    <item android:drawable="@drawable/white" />
</ripple>

We could also mask it using

<ripple android:color="#ff0000ff">
    <item android:drawable="@drawable/black" />
</ripple>

As mentioned in the document, the mask layer is not drawn on the screen, but just masking away the ripple effect. I'm curious, why should one set a color (White or Black or anything) there? Is there any significant of us setting a color as the Mask, or it is indeed any value will do?

Hopes someone enlighten... thanks!

Elye
  • 53,639
  • 54
  • 212
  • 474

1 Answers1

12

Using an opaque color for your mask -- whether that's @android:color/white, #ff000000, or #ff123456 doesn't matter -- means you are masking against a fully opaque rectangle that is the same size as your drawable. It's the most efficient rendering path for ripple masks.

alanv
  • 23,966
  • 4
  • 93
  • 80
  • Thanks @alanv. I tried #00000000 as well, the masking still works. Doesn't seems opaque on transparent change the masking effect. – Elye Jun 03 '15 at 09:44
  • That may be a bug in the fast path (or, more likely, in ColorDrawable.getOpacity()). On what version are you seeing that behavior? Have you tried M Preview? Assuming you don't have a separate `@android:id/mask` layer, using a transparent content layer ought to result in an invisible ripple because it's masked against an empty bitmap. – alanv Jun 03 '15 at 21:13
  • So you mean the color doesn't matter it's just the alpha that matters? – ATP Oct 10 '21 at 21:22