用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
-
Note: Remember that Android applies the first item in the state list that matches the current state of the object. So, if the first item in the list contains none of the state attributes above, then it is applied every time, which is why your
default value should always be last (as demonstrated in the following example).
部落格已搬到 http://marspring.mobi/