Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RippleDrawable mask color, what is it for?

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!

like image 475
Elye Avatar asked May 31 '15 10:05

Elye


People also ask

What is ripple color Android?

As you've noticed, ripples are used subtle indications of touch feedback, hence why they do not use colorPrimary or colorAccent by default. This is consistent with the changes made in Android 4.4 (Kitkat) which made the default selector colors neutral by default.

What is mask in ripple Android?

</shape> </item> </ripple> The use of the id @android:id/mask declares this as being a mask, and the mask defines the bounds for the ripple animation. I have included a solid fill within the shape drawable which defines the mask area.

What is RippleDrawable?

android.graphics.drawable.RippleDrawable. Drawable that shows a ripple effect in response to state changes. The anchoring position of the ripple for a given state may be specified by calling setHotspot(float, float) with the corresponding state attribute identifier.


1 Answers

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.

like image 64
alanv Avatar answered Oct 21 '22 17:10

alanv