赞
踩
Radiobutton的样式自定义无非就是style,然后在radiobutton中引用。
在style里面有相关属性:
background 来设置radiobutton的背景
button 来设置radiobutton的小框框, 当为null的时候,左边的按钮图片了
textcolor 来设置radiobutton的文字颜色
自定义的第一种style: 只修改radiobutton左边的按钮图片
<style name="CustomRadioBtn">
<item name="android:button">@drawable/mycustome_radio_selctor</item>
</style>mycustome_radio_selctor xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/enable_on_pressed" android:state_checked="true" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="@drawable/enable_off_pressed" android:state_checked="false" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="@drawable/enable_on" android:state_checked="true" android:state_enabled="true"/>
<item android:drawable="@drawable/enable_off" android:state_checked="false" android:state_enabled="true"/>
<item android:drawable="@drawable/disabled_on" android:state_checked="true" android:state_enabled="false"/>
<item android:drawable="@drawable/disabled_off" android:state_checked="false" android:state_enabled="false"/>
</selector>
第二种自定义样式style: 去除radiobutton左边的按钮图片,修改背景图
<style name="CustomRadioBtn2">
<item name="android:gravity">center</item>
<item name="android:background">@drawable/rb_nobtn_selector</item>
<item name="android:button">@null</item>
</style>rb_nobtn_selector xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/rb_pressed_bg" android:state_checked="true"></item>
<item android:drawable="@drawable/rb_normal_bg" android:state_checked="false"></item>
</selector>
还可以自定义textcolor,一样的方法啦。
顺便提一下 Selector state状态对应说明:
android:drawable 放一个drawable资源
android:state_pressed 是否按下,如一个按钮触摸或者点击。
android:state_focused 是否取得焦点,比如用户选择了一个文本框。
android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
android:state_checked 被checked了,如:一个RadioButton可以被check了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。