How to change the color of a CheckBox?
If your minSdkVersion
is 21+ use android:buttonTint
attribute to update the color of a checkbox:
<CheckBox
...
android:buttonTint="@color/tint_color" />
In projects that use AppCompat library and support Android versions below 21 you can use a compat version of the buttonTint
attribute:
<CheckBox
...
app:buttonTint="@color/tint_color" />
In this case if you want to subclass a CheckBox
don't forget to use AppCompatCheckBox
instead.
PREVIOUS ANSWER:
You can change CheckBox
s drawable using android:button="@drawable/your_check_drawable"
attribute.
you can set android theme of the checkbox to get the color you want in your styles.xml add :
<style name="checkBoxStyle" parent="Base.Theme.AppCompat">
<item name="colorAccent">CHECKEDHIGHLIGHTCOLOR</item>
<item name="android:textColorSecondary">UNCHECKEDCOLOR</item>
</style>
then in your layout file :
<CheckBox
android:theme="@style/checkBoxStyle"
android:id="@+id/chooseItemCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
unlike using android:buttonTint="@color/CHECK_COLOR"
this method works under Api 23
You can change the color directly in XML. Use buttonTint
for the box: (as of API level 23)
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/CHECK_COLOR" />
You can also do this using appCompatCheckbox v7
for older API levels:
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonTint="@color/COLOR_HERE" />