標籤:selector
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 預設情況,item必須放在最後 --> <!-- 非觸摸模式下獲得焦點並單擊時的背景圖片 --> <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/ic_launcher" /> <!-- 觸摸模式下單擊時的背景圖片--> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/ic_launcher" /> <!--選中時的圖片背景--> <item android:state_selected="true" android:drawable="@drawable/ic_launcher" /> <!--獲得焦點時的圖片背景--> <item android:state_focused="true" android:drawable="@drawable/ic_launcher" /> <item android:drawable="@drawable/button_bg_default" /></selector>
注意:
1、<!-- 預設情況,item必須放在最後 -->
This item is unreachable because a previous item (item #1) is a more general match than this one
不然會出現就是說第二行item之前,不能有元素出現。如果這樣放置,會出現按鈕一直是預設狀態,而無法獲得焦點的情況
安卓Selector詳細介紹