android 水波纹效果实现

枕上从妨一夜睡,灯前读尽十年诗。这篇文章主要讲述android 水波纹效果实现相关的知识,希望能为你提供帮助。
1.在drawable文件下,新建seletor,作为button的背景,这里我用的是两个圆角的shape

< ?xml version="1.0" encoding="utf-8"?> < selector xmlns:android="http://schemas.android.com/apk/res/android"> < item android:drawable="@drawable/shape_btn_cycle_normal"/> < item android:state_pressed="true" android:drawable="@drawable/shape_btn_cycle_press"/> < /selector>

 
shape_btn_cycle_normal
< ?xml version="1.0" encoding="utf-8"?> < shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> < corners android:bottomLeftRadius="20dp" android:bottomRightRadius="20dp" android:topLeftRadius="20dp" android:topRightRadius="20dp"/> < solid android:color="@color/colorWhite"/> < /shape>

shape_btn_cycle_press
< ?xml version="1.0" encoding="utf-8"?> < shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> < corners android:bottomLeftRadius="20dp" android:bottomRightRadius="20dp" android:topLeftRadius="20dp" android:topRightRadius="20dp"/> < solid android:color="@color/colorGray"/> < /shape>

【android 水波纹效果实现】 
2.在drawable-v21下,新建同selector名的ripple,如上,我的selector是selector_btn_cycle_bg,这里drawable-v21下新建selector_btn_cycle_bg.xml
< ?xml version="1.0" encoding="utf-8"?> < ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorGray"> //选中的水波纹的颜色 < item android:drawable="@drawable/shape_btn_cycle_normal"/> //未选中的背景状态< /ripple>

 

    推荐阅读