1. 程式人生 > >android 水波紋效果實現

android 水波紋效果實現

drawable color utf true odi lec .com enc orm

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>

android 水波紋效果實現