I am developing android application In that i use check box but default check box tick color is blue so i want to change that color to yellow. is there any inbuilt property to set color to check box tick.
12 Answers
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.

- 353
- 7
- 19

- 4,499
- 3
- 19
- 20
-
11
-
1you will have to have border around images to show box, one image will be empty border and other with the tick image – asok Buzz Feb 01 '16 at 17:21
-
Disappear because u used color changes in android:drawable="@drawable/checked". U need image! – ketom Jul 18 '17 at 11:05
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"

- 10,266
- 10
- 67
- 77
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. :)

- 325
- 3
- 6
-
1
-
I had to use: `cb.setButtonTintList(ColorStateList.valueOf(getResources() .getColor(R.color.colorAccent, null)));` – gig6 Jan 13 '21 at 18:10
Go to styles.xml and add this line.
<style>
<item name="colorAccent">@android:color/holo_green_dark</item>
</style>
using this you can change color or set different color

- 6,331
- 4
- 51
- 81
-
2seriosly your comment works fine but what have you written in your answer – Shekhar Oct 06 '15 at 04:57
-
2Wouldn't changing your theme change way more than just the checkboxes? – Nicolás Carrasco-Stevenson Feb 04 '16 at 14:47
-
@Nicolas Carrasco Well, as long as you create a id for this style and apply it only to the check-boxes it wouldn't... – SmugDoodleBug Jul 17 '19 at 00:27
If you want to change only tint color than must go with the below solution. Its work perfectly. Create a Selector "check_box_tint.xml" in your res/drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/your_checked_color" />
<item android:state_checked="false" android:color="@color/your_unchecked_color" />
</selector>
Now Use this drawable as color of your checkbox tint.
<CheckBox
android:id="@+id/cbSelectAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@drawable/check_box_tint"/>

- 1,413
- 1
- 13
- 17
Kotlin version:
checkBox.buttonTintList = ColorStateList.valueOf(R.color.colorPrimary)

- 170
- 1
- 13
Use Custom selector for the checkbox.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/patch_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/patch_normal" android:state_enabled="true"/>
<item android:drawable="@drawable/patchdisable" android:state_enabled="false"/>
</selector>
Like this.

- 3,623
- 2
- 29
- 36
For those still looking for an answer (I am aware this is an older question) – I found this solution works well without having to worry about API: https://stackoverflow.com/a/31840734/7601437
In short: create a style for the checkbox, e.g. checkboxStyle
and then implement it as a theme: android:theme="@style/checkboxStyle"

- 121
- 14
Firstly, we must create a drawable that include checked and uncheck color situations, then you must set this drawable as buttonTint;
drawable_checkbox;
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/kelleyGreen" />
<item android:state_checked="false" android:color="@color/warmGrey" />
</selector>
<style name="CheckBox" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:textAppearance">@style/TextAppearance.Regular.XSmall</item>
<item name="android:textColor">@color/warmGrey</item>
<item name="buttonTint">@drawable/drawable_checkbox</item>
</style>

- 1,253
- 16
- 17
For applying color programmatically it will require API Level >19 if your min sdk is >19 then you can use
checkbox[i]!!.setButtonTintList(getColorStateList(activity!!,R.color.green))
OR
view.setButtonTintList(getColorStateList(activity!!,R.color.green))

- 101
- 3
If nothing works than use AppCompatCheckBox with app:buttonCompat="your_drawable_selector"
This is working with png.

- 872
- 1
- 16
- 43