Checkbox选框样式

一、自定义CheckBox样式

*res/drawable文件夹下定义selector_checkbox.xml样式文件

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

res/layout文件夹下xml文件中引用selector样式

<CheckBox
   android:id="@+id/cb_stulogin"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="记住密码"
   android:textColor="#ffffff"
   android:textSize="12dp"
   android:button="@drawable/checkbox_style"
   android:paddingLeft="@dimen/stulogin_checkbox_padding"/>

注:paddingLeft用于设置CheckBox中选框和文字之间的距离

二、修改CheckBox颜色

res/values/colors.xml 文件中定义两种颜色

<color name="white">#ffffff</color>
<color name="inputbox_blue">#4b84b7</color>

res/values/styles.xml 文件中定义theme样式资源

<resources>

    <style name="CheckBox" parent="Theme.AppCompat.Light">
        <item name="colorControlNormal">@color/white</item><!-- 未选中颜色 -->
        <item name="colorControlActivated">@color/inputbox_blue</item><!-- 选中颜色 -->
    </style>
</resources>

res/layout文件夹下xml文件中引用主题样式

<CheckBox
        android:layout_width="@dimen/inputbox_width"
        android:layout_height="wrap_content"
        android:theme="@style/CheckBox"
        android:checked="true"
        android:text="@string/remember_customer"/>

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值