Android 自定义CheckBox样式

来源:互联网 发布:网络课程哪个好 编辑:程序博客网 时间:2024/05/27 16:43

原文地址:https://www.cnblogs.com/Claire6649/p/5941145.html


1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。

复制代码
 1 <selector xmlns:android="http://schemas.android.com/apk/res/android" > 2     <item  3         android:drawable="@drawable/sel_check" 4         android:state_checked="true"/> 5     <item 6         android:drawable="@drawable/sel_nor" 7         android:state_checked="false"/> 8     <item 9         android:drawable="@drawable/sel_nor"/>10 11 </selector>
复制代码

 

2.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式。

 

1  <!-- CustomCheckBox theme -->2     <style name="CustomCheckBoxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">3         <item name="android:button">@drawable/checkbox_style</item> 4     </style>

 

3.在布局文件中使用CustomCheckBoxTheme样式。

 

复制代码
1 <CheckBox2                 android:id="@+id/tv_upper"3                 android:layout_width="wrap_content"4                 android:layout_height="wrap_content"5                 android:gravity="center_vertical"6                 style="@style/CustomCheckBoxTheme" />
复制代码

 

 

使用到的图片资源

 

 

sel_check.png

sel_nor.png


原创粉丝点击