自定义CheckBox或者RadioButton样式

来源:互联网 发布:淘宝量子统计没有了 编辑:程序博客网 时间:2024/05/21 00:21

在项目中经常会碰到需要自定义的CheckBox或者RadioButton,这里介绍一下:

1.首先定义一个图片选择器:

selector_setting_checkbox.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/checkbox_setting_on" android:state_checked="true"/>    <item android:drawable="@drawable/checkbox_setting" android:state_checked="false"/>    <!-- <item android:drawable="@drawable/checkbox_normal"/> --></selector>


2. 在styles.xml中添加样式

<style name="setting_checkbox" parent="@android:style/Widget.CompoundButton.CheckBox">        <item name="android:button">@drawable/selector_setting_checkbox</item>      </style> 

3. 使用的时候给CheckBox或者RadioButton添加这个样式即可:

         <RadioButton             android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="@string/clound_album_mode_public"            style="@style/setting_checkbox"            android:textColor="@color/common"            android:textSize="18dip"              />


原创粉丝点击