Android实现水波纹点击效果

  

Android实现水波纹点击效果只在Android5.0以上版本有效,水波纹点击效果代码供大家参考,具体内容如下

  

 Android实现水波纹点击效果”> <br/>
  </p>
  <p>圆角背景的水波纹效果(如上图)</p>
  <p> <强> 1。定义一个普通圆角背景的xml; </强> <br/>
  </p>
  <p> rounded_corners。xml <br/>
  </p>
  
  <pre类=   & 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实现水波纹点击效果