您现在的位置是:首页 > 文章详情

Android 怎么制作按钮点击的波纹?

日期:2020-07-20点击:358

在安卓的  Mixnum API Level  为5.0的项目里,设计一个按钮的背景色,但设置背景色后,发现它的点击的波纹动画效果没有了,于是搜索根据网上教程复制了一个,但不太懂怎么弄,

不过波纹效果到是实现了,但是效果不太好,表现是这样的,用户单击按钮。背景就是闪成透明一下。只有长按按钮才能稍微看到点波纹效果。怎么实现像系统自带的Button的点击动画的波纹效果一样?

xml代码如下:

点击背景效果设置

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false"> <shape > <!-- 背景色 --> <solid android:color="@color/colorPrimary"/> </shape> </item> <item android:drawable="@drawable/ripple_bg" android:state_pressed="true"> </item> </selector>

波纹效果 ripple_bg文件内容

<ripple xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:color="@color/colorPrimary" tools:targetApi="lollipop"> <item android:id="@android:id/mask"> <shape android:shape="rectangle"> <solid android:color="@color/colorPrimary" /> </shape> </item> </ripple>

 

原文链接:https://www.oschina.net/question/4102619_2317570
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章