自定义CheckBox样式

自定义CheckBox样式

效果一

1.1控件属性

<CheckBox
    style="@style/AlarmDateCheckBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="一" />

由于控件使用次数较为频繁,所以使用style属性统一设置。

<style name="AlarmDateCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:gravity">center</item>
    <item name="android:layout_margin">4dp</item>
    <item name="android:button">@null</item>
    <item name="android:background">@drawable/date_bg</item>
    <item name="android:textSize">@dimen/item_txt_size</item>
    <item name="android:textColor">@drawable/date_text</item>
</style>

说明:
1. button:设置图片资源。
2. background:设置背景资源。
3. textColor:设置字体颜色。

1.2background

2.1 date_bg_checked.xml

2.2 date_bg_unchecked.xml

2.3 date_bg.xml

1.3textColor

date_text.xml

效果二

准备两张图片,选中状态与未选中状态。


2.1 控件属性

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:button="@drawable/register_agreement_cb"/>

2.2 button属性资源

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值