Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

android - Create a ripple drawable without transparency

I'm a bit lost about how to properly use Ripple Drawable.

Let's say I have this drawable :

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
     <item android:state_pressed="false" android:state_focused="true" android:drawable="@color/accent_color_light" />
     <item android:state_pressed="true" android:drawable="@color/accent_color_light" />
     <item android:drawable="@android:color/white" />
</selector>

So it is a plain white background which changes to a light blue when it is focused or pressed.

How can I get the same colors but with a ripple effect ? I think I need to use a mask to prevent it from getting outside the bounds of the view ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Forgot to answer my own question.

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
   android:exitFadeDuration="@android:integer/config_shortAnimTime"
   android:color="@color/my_color" >

   <item android:id="@android:id/mask">
       <shape android:shape="rectangle" >
           <solid android:color="@android:color/holo_green_light" />
       </shape>
    </item>

</ripple>

The color in the item with the id "mask" is not displayed. It is used to tell the shape and bounds of the ripple effect. Without it, it can go outside the bounds of the view.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...