自定义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"/>