How can I disable Android Lollipop ripple's alpha value?

时光怂恿深爱的人放手 提交于 2021-02-17 21:25:58

问题


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.

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.


回答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>


来源:https://stackoverflow.com/questions/33217896/how-can-i-disable-android-lollipop-ripples-alpha-value

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