Create a ripple drawable without transparency

核能气质少年 提交于 2019-11-29 01:58:29

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.

RippleDrawable is already a StateListDrawable (ie selector) - so you can just use a ripple drawable as your background (with a default state) - something like this:

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

the mask piece bounds the ripple (and, in reality, the above snippet, minus the colors and the last android:drawable which sets the non-pressed background) is the default list selector used in lollipop.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!