How to change check box tick color in android
You can use the attribute app:buttonTint
of the AppCompatCheckBox
from the android.support.v7 library.
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonTint="@color/colorAccent"/>
Advantage: works also below API 21 and you don't need to redraw the checkbox.
As of API 21 you can use the Button Tint attribute
android:buttonTint="#FFFF00"
If you want to do this programmatically, then you simply do this:
final CheckBox cb = new CheckBox(getApplicationContext());
cb.setButtonTintList(getColorStateList(R.color.colorAccent));
Chris Stillwell's answer gave me the idea to try this as I couldn't simply set the colour using the attributes. :)
Unfortunately, changing the color of checkbox check mark isn't a simple attribute
Create a selector xml file in res\drawables\
folder with name cb_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/checked" />
<item android:state_checked="false" android:drawable="@drawable/unchecked" />
</selector>
In your layout file apply this file to your checkBox
<CheckBox
android:id="@+id/cb"
android:text="My CheckBox"
android:button="@drawable/cb_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Add a unchecked.png
, and checked.png
in your drawables
folder. These are checked and unchecked image of checkbox.