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>
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>
3.imgbutton 使用水波纹,要将水波纹设置在src上,设置在background上会被src遮盖