如何禁用Android Lollipop涟漪的Alpha值? [英] How can I disable Android Lollipop ripple's alpha value?

查看:395
本文介绍了如何禁用Android Lollipop涟漪的Alpha值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种使用自定义颜色的波纹.但是,颜色永远不会完全不透明.根据

您可以在 https://github.com/gradha/Stackoverflow33217896

上找到波纹效应的简单示例a>使用XML涟漪图,另一个通过代码生成.后者表明不重写代码就不可能实现不透明的波纹.

您可以简单地将alpha值用于有界波纹.

 <波纹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> 

无限波纹,如果您知道强调色,则可以设置颜色的不透明性

 <波纹xmlns:android ="http://schemas.android.com/apk/res/android"android:color ="@ color/accent_26"/> 

colors.xml

 < resources>...<颜色名称="accent">#ff33b5e5</color><颜色名称="accent_alpha26">#4233b5e5</color></resources> 

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.

解决方案

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>

这篇关于如何禁用Android Lollipop涟漪的Alpha值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆