Android Ripple:其他应用如何使它们的波纹如此透明而不影响视图的原始颜色 [英] Android Ripple: How do other apps make their ripple so transparent without affecting the original colour of the view

查看:120
本文介绍了Android Ripple:其他应用如何使它们的波纹如此透明而不影响视图的原始颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您查看其他应用程序(例如yPlan或Google Play商店)时,它们在按钮上的波纹效果就像浅灰色或黑色,不会改变整个按钮的颜色.

When you look at other apps like yPlan or Google Play Store, their ripple effect on buttons is like a light grey or black that does not change the colour of the whole button.

我想要同样的效果.

这是我尝试过的方法,但不相同

Here is what i tried but its not the same

这是我的色彩控制亮点:它是具有99%alpha的灰色

This is my colour control highlight: Its a grey with 99% alpha

    <color name="colorHighlight">#fc8c969f</color>

这是我的纽扣抽屉

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

请注意,由于我无法两次使用android:background,因此drawable将按钮的颜色设为黄色

Note the drawable is to make the colour of the button yellow since i cant use android:background twice

推荐答案

<?xml version="1.0" encoding="utf-8"?>
<!--Use an almost transparent color for the ripple itself-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#22000000"> 

    <!--Use this to define the shape of the ripple effect (rectangle, oval, ring or line). The color specified here isn't used anyway-->
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="#000000" /> 
        </shape>
    </item>

    <!--This is the background for your button-->
    <item>
        <!--Use the shape you want here-->
        <shape android:shape="rectangle">
            <!--Use the solid tag to define the background color you want (here yellow)-->
            <solid android:color="#ffff00"/> 
            <!--Use the stroke tag for a border-->
            <stroke android:width="1dp" android:color="#ffff00"/>
        </shape>
    </item>
</ripple>

这篇关于Android Ripple:其他应用如何使它们的波纹如此透明而不影响视图的原始颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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