1. 程式人生 > >【日常新手入門】android之點選變色

【日常新手入門】android之點選變色

實現點選button改變button的顏色只需要在drawable中新增selector.xml檔案即可

<selector xmlns:android="http://schemas.android.com/apk/res/android">
       
        <item android:state_pressed="true"       //點選獲取
        android:drawable="@drawable/btn_index_in_normal"/>
         <item
        android:drawable="@drawable/btn_index_in_select"/>
       

</selector>

注意!正常情況的item要編寫在點選事件下面,不然是出現不了點選效果的。

然後在button的background改變為android:background="@drawable/selector1"即可

就能順利實現按鈕點選變色效果了