在ImageButton外部实现波纹效果 [英] Implementing Ripple effect outside ImageButton

查看:288
本文介绍了在ImageButton外部实现波纹效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为ImageButton实现涟漪效果.我已经在背景中设置了涟漪,并在src中设置了可绘制图像.

I am trying to implement ripple effect for ImageButton.I have set ripple in background and drawable image in the src for it.

android:background="@drawable/myripplexml"
android:src="@drawable/myimagepath"

它在按钮布局内提供了很好的波纹效果.但是我也希望波纹效果也可以扩展到Button Layout之外.另一种方法是使用:

Its giving nice ripple effect inside button Layout. But I want Ripple effect to extend outside the Button Layout also.Another way to do it is using :

 android:background="?android:attr/selectableItemBackgroundBorderless"

但是它使用默认的颜色和样式.如何针对颜色,形状和大小自定义它?

But it uses default color and style. How can I customize it regarding color, shape and it's size ?

推荐答案

我遇到了这个问题,我的问题是"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.

这篇关于在ImageButton外部实现波纹效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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