炫酷的MaterialDesign Ripple水波纹动画效果

google在android 5.0上加入了触摸反馈动画(Ripple),设置成功后,点击控件的时候会从点击位置产生一圈水波纹的扩散效果

  • 使用系统自带资源在XML文件上配置Ripple动画

    //波纹有边界
    android:background="?android:attr/selectableItemBackground" 
    
    //波纹可以扩散出边界
    android:background="?android:attr/selectableItemBackgroundBorderless"
    
  • 自定义drawable配置Ripple动画

    1. 自定义drawable

      
       
           //按下时的水波纹颜色
      
      

    2. 在代码上配置动画资源

      if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
        btnTest.setBackgroundResource(R.drawable.ripple);
      }
      
  • 相关文档

    • AndroidDeveloper:
      https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html

你可能感兴趣的:(炫酷的MaterialDesign Ripple水波纹动画效果)