Android CheckBox设置背景selector和文本text 设置selectColor

1. android:button="@null" 可以屏蔽CheckBox的选择框

2.android:textColor="@drawable/selector_text_color"  文本text 设置selectColor

效果图:

Android CheckBox设置背景selector和文本text 设置selectColor

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dp_36"
            android:layout_marginRight="@dimen/dp_36"
            android:orientation="vertical">

            <CheckBox
                android:id="@+id/course_checkbox"
                android:layout_width="match_parent"
                android:layout_height="@dimen/edit_box_height"
                android:layout_marginTop="@dimen/dp_10"
                android:gravity="center"
                android:button="@null"
                android:background="@drawable/selector_btn_checkbox"
                android:textColor="@drawable/selector_text_color"
                android:textSize="@dimen/sp_18"
                android:text="课程类"
                />

            <CheckBox
                android:id="@+id/article_checkbox"
                android:layout_width="match_parent"
                android:layout_height="@dimen/edit_box_height"
                android:layout_marginTop="@dimen/dp_10"
                android:gravity="center"
                android:button="@null"
                android:background="@drawable/selector_btn_checkbox"
                android:textColor="@drawable/selector_text_color"
                android:textSize="@dimen/sp_18"
                android:text="文章类" />

        </LinearLayout>

drawable/selector_text_color.xml

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

    <item android:color="@color/colorAccent" android:state_checked="true"/>
    <item android:color="#ff979797" android:state_checked="false" />

</selector>

同样适用于RadioButton


上一篇:Android 初识Retrofit


下一篇:HaaS100开发调试系列 之 定位AliOS Things内存及Crash问题