且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在ImageButton外部实现波纹效果

更新时间:2023-11-17 13:44:10

我遇到了这个问题,我的问题是"selectableItemBackgroundBorderless"创建了一个矩形,而我的按钮却是圆形的.我不确定这是否能回答原始问题,但这是我发现的内容:在drawable-v21

I ran into this and my issue is that 'selectableItemBackgroundBorderless' creates a rectangle, while my button was circular. I'm not sure if this answers the original question but here is what I found: set the background to this in drawable-v21

<ripple
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?android:colorControlHighlight">
    <item android:id="@android:id/mask">
        <shape android:shape="oval">
            <solid android:color="?android:colorAccent" />
        </shape>
    </item>
</ripple>

在较低的api级别中

和@null(假设您使用的是实际图像按钮src的选择器).在按钮的填充中最明显的波纹.如果根本没有遮罩层,涟漪是***的,并且会占据整个屏幕.您可以使用任何想要的形状(如果不是圆形的话).

and @null in lower api levels (assuming you're using a selector for the actual image button src). The ripple most visible in the padding of the button. If there's no masking layer at all The ripple is unbound and kind of takes over the whole screen. You can use whatever shape you want if not a circle.