Button的Ripple Effect实现

发布时间:2024-08-21 17:19:19 作者:小樊
来源:亿速云 阅读:79

在Android中实现Button的Ripple Effect可以通过使用Selector和Ripple Drawable来实现。以下是一个示例代码示例:

  1. 首先,在res/drawable目录下创建一个button_ripple.xml文件,定义Button的Ripple效果:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorControlHighlight">
    <item android:id="@android:id/mask" android:drawable="@android:color/white" />
    <item android:drawable="@drawable/button_bg" />
</ripple>
  1. 接着在res/drawable目录下创建一个selector_button.xml文件,定义Button的Selector效果:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/button_ripple" />
    <item android:drawable="@drawable/button_bg" />
</selector>
  1. 最后,在布局文件中使用该Selector效果的Button:
<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/selector_button"
    android:text="Button with Ripple Effect" />

这样就可以实现一个带有Ripple Effect的Button。当用户点击Button时,会显示出水波纹效果。

推荐阅读:
  1. IOS 水波纹 ripple
  2. css3实现3D动画导航栏的示例

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

button

上一篇:Button在布局中的对齐与分布

下一篇:Button的文本与图标结合显示

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》