具有透明背景形状的涟漪

具有透明背景形状的涟漪

本文介绍了具有透明背景形状的涟漪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用中使用了以下形状

I am using the following shape in my app

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="oval" >
            <solid android:color="@color/primary_light"/>
            <size android:height="80dp" android:width="80dp"/>
        </shape>
    </item>

    <item android:state_focused="true">
        <shape android:shape="oval">
            <stroke android:color="@color/primary_light" android:width="5dp"/>
            <size android:height="80dp" android:width="80dp"/>
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <solid android:color="@android:color/transparent"/>
            <size android:height="80dp" android:width="80dp"/>
        </shape>
    </item>
</selector>

它在我的可绘制文件夹中.现在,我正在将我的应用程序更新为Lollipop,希望对使用的圆形按钮给出反馈.因此,在drawable-v21文件夹中,我将其更改为波纹选择器:

It is there in my drawable folder. Now I am updating my app to Lollipop and I wish to give a ripple feedback on the circular button that I used.So in drawable-v21 folder I changed it to a ripple selector:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/primary_light">
    <item>
        <selector>
            <item android:state_focused="true">
                <shape android:shape="oval">
                    <stroke android:color="@color/primary_light" android:width="5dp"/>
                    <size android:height="80dp" android:width="80dp"/>
                </shape>
            </item>

            <item android:id="@android:id/mask">
                <shape android:shape="oval">
                    <solid android:color="@android:color/transparent"/>
                    <size android:height="80dp" android:width="80dp"/>
                </shape>
            </item>
        </selector>
    </item>
</ripple>

但是不幸的是,通过在棒棒糖中使用上述可绘制图形不会产生波纹效果.是因为<solid android:color="@android:color/transparent"/>吗?

But unfortunately the ripple effect is not generated by using the above drawable in Lollipop. Is it because of the <solid android:color="@android:color/transparent"/>?

有人可以告诉我我哪里出问题了吗?谢谢

Can anyone show me where I have go wrong? Thanks

推荐答案

经过几次试验和错误,看来我误解了selectoritem的层次结构.

After a few trial and errors it seems I have misunderstood the hierarchy of the selector and item.

以下内容可以很好地发挥作用.

The following works perfectly.

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/primary_light">
        <item android:id="@android:id/mask">
               <shape android:shape="oval">
                       <solid android:color="@android:color/white"/>
                       <size android:height="80dp" android:width="80dp"/>
               </shape>
        </item>
</ripple>

这篇关于具有透明背景形状的涟漪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:56