您的位置:首页 > Web前端 > CSS

自定义CheckBox和RadioButton的样式

2016-04-23 22:02 501 查看
在drawable文件下新建一个selector_checkbox.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/check_normal" android:state_checked="false" />
<item android:drawable="@drawable/check_checked" android:state_checked="true" />
</selector>


在values文件下新建一个custom_style.xml

<resources>
<!--自定义checkbox样式-->
<style name="custom_checkbox_style">
<item name="android:button">@drawable/selector_check</item>
</style>
<!--自定义radiobutton样式-->
<style name="custom_radiobutton_style">
<item name="android:button">@drawable/selector_check</item>
</style>
</resources>


在布局文件中引入自定义样式

<CheckBox
android:id="@+id/checkbox"
style="@style/custom_checkbox_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/checkbox" />

<RadioButton
android:id="@+id/radio_button"
style="@style/custom_radiobutton_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radiobutton" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: