Android实现水波纹点击效果只在Android5.0以上版本有效,水波纹点击效果代码供大家参考,具体内容如下
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;形状xmlns: android=" http://schemas.android.com/apk/res/android " android:形状=熬匦巍北? & lt;固体android:颜色=" # FFFFFF "/比; & lt;角落android:=" 4 dp/半径比; & lt;/shape> >之前
2。这里是重点,& lt; ripple>是API21才有的新标签,正是<>强实现水波纹效果>强劲的;
其中这个是指定水波纹的颜色,而里面的东西,我们都很熟悉,就是普通的定义一个带圆角的背景。
ripple_bg。xml:
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;脉动xmlns: android=" http://schemas.android.com/apk/res/android " android:颜色=" # FF21272B”比; & lt; item> & lt;形状android:形状=熬匦巍北? & lt;固体android:颜色=" # FFFFFF "/比; & lt;角落android:=" 4 dp/半径比; & lt;/shape> & lt;/item> & lt;项目android:可拉的=癅drawable/rounded_corners”/比; & lt;/ripple> >之前<强> 3。这是活动的布局xml 强>,
直接使用ripple_bg作为背景。
activity_main.xml
& lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:工具=" http://schemas.android.com/tools " android: layout_width=" match_parent " android: layout_height=" match_parent " android:重力="中心" android:取向=按怪薄? android: paddingBottom=" @dimen/activity_vertical_margin” android: paddingLeft=" @dimen/activity_horizontal_margin” android: paddingRight=" @dimen/activity_horizontal_margin” android: paddingTop=" @dimen/activity_vertical_margin” 工具:上下文=?MainActivity”比; & lt; TextView android: layout_width=" wrap_content " android: layout_height=" wrap_content " android:文本=癅string/hello_world”/比; & lt;按钮 android: layout_width=" match_parent " android: layout_height=" wrap_content " android:背景=" @drawable/ripple_bg” android:文本=癅string/hello_world”/比; & lt;/LinearLayout> >之前以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
Android实现水波纹点击效果