自定义CheckBox样式

640?wx_fmt=gif

640?wx_fmt=gif

640?wx_fmt=other

极力推荐文章:欢迎收藏Android 干货分享 

640?wx_fmt=other

本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:

  1. 自定义样式

  2. 自定义选择器效果

  3. 自定义素材

  4. 为CheckBox标签自定义样式

Android中自带的CheckBox 样式比较丑,为了美化CheckBox可使用一下方法。

640?wx_fmt=other

未选中状态

640?wx_fmt=jpeg

选中状态

1. 自定义样式

values中自定义Style样式(CustomCheckboxTheme)

    <!-- 自定义CheckBox 样式 -->
    <style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
        <item name="android:button">@drawable/custom_checkbox_selector</item>
    </style>

2. 自定义选择器效果

自定义选择器,可以实现不同状态下显示不同的图片custom_checkbox_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/btn_checkbox_press" android:state_checked="true"/>
    <item android:drawable="@drawable/btn_checkbox_normal" android:state_checked="false"/>
    <item android:drawable="@drawable/btn_checkbox_normal"/>

</selector>

3. 自定义素材

640?wx_fmt=other

btn_checkbox_press.png

640?wx_fmt=other

btn_checkbox_normal.png

4. 为CheckBox标签自定义样式

CheckBox设置自定义样式 CustomCheckboxTheme

    <CheckBox
        
        android:layout_width="wrap_content"
        android:layout_height="45dp"
        android:text="自定义Checkbox样式" />

640?wx_fmt=jpeg

640?wx_fmt=jpeg

长按识别二维码,领福利

至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

如有侵权,请联系小编,小编对此深感抱歉,届时小编会删除文章,立即停止侵权行为,请您多多包涵。

640?wx_fmt=gif

640?wx_fmt=png

posted @ 2019-04-17 12:10  程序员Android的博客  阅读(102)  评论(0编辑  收藏  举报