android RadioButton注意事項

來源:互聯網
上載者:User
用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/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.