【android】RadioButton定制


android自帶的RadioButton樣式實在是不好看。如果只是需要修改RadioButton前面的圓圈樣式,則:

(1)在drawable文件夾下增加文檔myradiobutton.xml,描述button在各個狀態下得圖片:

<?xml version="1.0" encoding="utf-8"?>
<selector
	xmlns:android="http://schemas.android.com/apk/res/android"
	>
	<item
		android:state_focused="false"
		android:state_checked="false"
		android:state_pressed="false"
		android:drawable="@drawable/search_radio"
		>
	</item>
	<item
		android:state_focused="false"
		android:state_checked="true"
		android:state_pressed="false"
		android:drawable="@drawable/search_radio_sel"
		>
	</item>
	<item
		android:state_focused="true"
		android:state_checked="false"
		android:state_pressed="false"
		android:drawable="@drawable/search_radio_onfocus"
		>
	</item>
	<item
		android:state_focused="true"
		android:state_checked="true"
		android:state_pressed="false"
		android:drawable="@drawable/search_radio_onfocus_sel"
		>
	</item>
</selector>

 

(2)然后在布局文件中修改Radiobutton屬性(android:button):

	<RadioButton
		android:id="@+id/rb_5"			
		android:layout_width="120px"
		android:layout_height="85px"
		android:button="@drawable/myradiobutton"
	/>

這樣就OK了。

 

還有其他的方法,

(1)重寫Radiobutton,參考http://hi.baidu.com/545057627/blog/item/bd154f0bfef4e5181c9583d6.html

(2)修改Radiobutton的style屬性,如附件:myAnimation.zip


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM