Android 自定义CheckBox样式


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 <CheckBox
2                 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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM