用RadioButton做個小控件,用selector作了個背景,selector裏item的聲明竟然要有順序,好惡心。所以以後遇到定義的selector不管用 得注意下
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/btn_left_selected"/>
<item android:state_pressed="true"
android:drawable="@drawable/btn_left_selected"/>
<item android:drawable="@drawable/btn_left"/>
</selector>
如果第三個item你放到第一個位置的話 你選擇某個RadioButton,他的背景色不會變,我這裏沒有一一去試,遇到情況再說
還有如果不要默認的小圓圈背景,在RadioButton控件里加個屬性 android:button="@null",使其背景屬性爲透明
此外,RadioButton的checked屬性設置爲true,代碼裏調用RadioButton的check(id)方法,不會觸發onCheckedChanged事件
至於爲什麼 我在api文檔裏找到解釋
the selection is not based
on the "best match," but simply the first item that meets the minimum criteria of the state.
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
博客已搬到 http://marspring.mobi/