How do I change the default CheckBox
color in Android?
By default the CheckBox
color is green, and I want to change this color.
If it is not possible please tell me how to make a custom CheckBox
?
-
1Are you trying to change the font's color? Or the color of the actual box? – May 02 '11 at 06:28
-
1actual box color i change – Piyush Jul 30 '14 at 06:46
-
89Setting the `android:buttonTint="@color/mybrown"` is an easy way to change the box color. – shauvik Jun 24 '15 at 22:53
-
6@Shauvik it just working on material design :) – Mucahit Jul 13 '15 at 13:30
-
11@shauvik it's better to use `app:buttonTint="@color/mybrown"` instead, this way it can work on API < 21 – Nikaoto Aug 06 '17 at 12:52
-
`app:buttonTint` is a good solution for API < 21, but you'll also need to use `android.support.v7.widget.AppCompatCheckBox` – rjr-apps Jan 17 '18 at 17:06
-
@shauvik easy for >= 21.. many things are easy for >= 21... – user25 Apr 29 '18 at 09:48
26 Answers
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" />

- 1,711
- 3
- 13
- 23

- 5,993
- 2
- 20
- 28
-
8Nice, thanks! And don't forget to add _xmlns:app="http://schemas.android.com/apk/res-auto"_ to your main/parent layout – Alberto Méndez Mar 15 '16 at 11:45
-
2
-
1This will automatically be used when you use CheckBox in your layouts. You should only need to manually use this class when writing custom views. – 최봉재 Apr 12 '17 at 09:22
-
4
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.

- 53,859
- 22
- 133
- 139
-
7You'd have to create your own drawable. There's gotta be a more straight-forward way... – IgorGanapolsky Sep 14 '16 at 16:07
-
14Changing buttonTint colour is a more straight forward way. We have to use the native elements instead customising it unnecessarily. – Neela Aug 06 '17 at 13:14
-
The value of `buttonTint` seems to override the `textColor` value. Any ideas how to work around this? – Alex Semeniuk Jul 17 '20 at 14:47
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

- 3,395
- 3
- 23
- 36
-
7TEXTCOLORSECONDARY!!!! THank you man! That's it. I searched for ages to just change the unselected background color and did not want to work with custom drawables. This is it! – Mulgard May 27 '16 at 07:53
-
-
2Worked for me, but needed to add to the CheckBox xml to be able to see the text - android:textColor="@color/textColor" – Zvi Jun 13 '16 at 18:32
-
-
1
-
I used `app:buttonTint="@color/CHECK_COLOR"` instead of `android` prefix and it worked fine in my pre-lollipop device – Shashanth Jul 21 '16 at 13:26
-
-
-
-
Note: For material design styling, there is the `contentControl` options now: https://materialdoc.com/components/selection-controls/ – SimpsOff Aug 09 '18 at 14:15
-
-
I am trying to use this in React Native. Where should I place the
field? – Surendra Pathak Jan 14 '19 at 08:18 -
-
Use buttonTint
to change color of button and color selector for above 21+ api version.
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonTint="@color/checkbox_filter_tint"
tools:targetApi="21"/>
res/colors/checkbox_filter_tint.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/light_gray_checkbox"
android:state_checked="false"/>
<item android:color="@color/common_red"
android:state_checked="true"/>
</selector>

- 1,605
- 13
- 31

- 2,285
- 1
- 13
- 16
-
3
-
-
1
-
1This seems to be the only simple approach for setting both the checked and unchecked colors that works on all devices. – Gumby The Green Jul 02 '19 at 20:54
-
2This should be the accepted answer. Although it should be noted that it doesnt work when the selector is declared as a `values` resource. As indicated by the path shown above, it has to be inside the `colors` resource folder. – Benjamin Basmaci Dec 03 '19 at 12:36
Programmatic version:
int [][] states = {{android.R.attr.state_checked}, {}};
int [] colors = {color_for_state_checked, color_for_state_normal}
CompoundButtonCompat.setButtonTintList(checkbox, new ColorStateList(states, colors));

- 5,499
- 2
- 48
- 64

- 6,893
- 3
- 39
- 55
-
2
-
1it gave me unexpected result with colors, are you sure you didn't confuse anything? – Kirill Karmazin Oct 22 '18 at 11:50
-
@Carlos This is not a "better" solution, because in android you should always try to set all the layout stuff in the xml file and not programmatically except when you need to change it dynamically – kyay10 Feb 08 '19 at 22:38
-
2@kyay Not "always" ... the Android resource system is a mess and often doing it programmatically is far easier and more maintainable. – nyholku Feb 09 '19 at 08:41
-
-
@kyay10 that's absolutely a wrong statement. If you think the opposite then take a look about what's happening with Jetpack Compose. – Joaquin Iurchuk Nov 04 '22 at 22:26
I would suggest to use he style approach in android as the way to configure built-in android views, add new style in your project:
<style name="yourStyle" parent="Base.Theme.AppCompat">
<item name="colorAccent">your_color</item> <!-- for uncheck state -->
<item name="android:textColorSecondary">your color</item> <!-- for check state -->
</style>
and add assign this style to the theme of the checkbox: android:theme="@style/youStyle"
hope this helps.

- 211
- 2
- 3
-
agree with this solution, those attributes should work better with the default built-in android component without hassle on the drawable like the upvoted answer. – Trung Le Mar 14 '17 at 04:38
-
1
-
Add buttonTint in your xml
<CheckBox
android:id="@+id/chk_remember_signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/hint_chk_remember_me" />

- 6,739
- 6
- 37
- 57
-
2The content of this answer already exists in [afathman's answer](http://stackoverflow.com/a/33834496/1813169). – MTCoster Jul 29 '16 at 12:52
Add this line in your styles.xml
file:
<style>
<item name="android:colorAccent">@android:color/holo_green_dark</item>
</style>

- 12,245
- 6
- 43
- 74

- 6,331
- 4
- 51
- 81
-
-
4
-
-
1On Galaxy S3 it changes only checked state of a CheckBox. But unchecked state is still the same. – Slava May 15 '17 at 17:53
Me faced same problem, I got a solution using below technic. Copy the btn_check.xml
from android-sdk/platforms/android-#(version)/data/res/drawable
to your project's drawable folder and change the 'on' and 'off' image states to your custom images.
Then your xml will just need android:button="@drawable/btn_check"
<CheckBox
android:button="@drawable/btn_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
If you want to use different default Android icons, you can use:
android:button="@android:drawable/..."
-
Great answer - much easier than creating custom xml .. thanks! For me, I have a gray background and the checkbox border was not visible. I added this and you can see it now: android:button="@android:drawable/checkbox_off_background" – Gene Bo Apr 23 '15 at 16:24
-
1There's actually a bit more to using this approach than I realized .. but still a nice option. I have added details below http://stackoverflow.com/a/29831532/2162226 – Gene Bo Apr 23 '15 at 18:27
buttonTint worked for me try
android:buttonTint="@color/white"
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/agreeCheckBox"
android:text="@string/i_agree_to_terms_s"
android:buttonTint="@color/white"
android:layout_below="@+id/avoid_spam_text"/>

- 14,011
- 2
- 83
- 54
create an xml Drawable resource file
under res->drawable
and name it, for example, checkbox_custom_01.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/checkbox_custom_01_checked_white_green_32" />
<item
android:state_checked="false"
android:drawable="@drawable/checkbox_custom_01_unchecked_gray_32" />
</selector>
Upload your custom checkbox image files (i recommend png) to your res->drawable
folder.
Then go in your layout file and change your checkbox to
<CheckBox
android:id="@+id/checkBox1"
android:button="@drawable/checkbox_custom_01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="CheckBox"
android:textSize="32dip"/>
you may customize anything, as long as android:button
points to the correct XML file you created before.
NOTE TO NEWBIES: though it is not mandatory, it is nevertheless good practice to name your checkbox with a unique id throughout your whole layout tree.

- 9,424
- 6
- 76
- 100
You can change checkbox
color using singe line of code
android:buttonTint="@color/app_color" //whatever color

- 946
- 11
- 27

- 2,394
- 1
- 19
- 15
100% robust approach.
In my case, I didn't have access to the XML layout source file, since I get Checkbox from a 3-rd party MaterialDialog lib. So I have to solve this programmatically.
- Create a ColorStateList in xml:
res/color/checkbox_tinit_dark_theme.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white"
android:state_checked="false"/>
<item android:color="@color/positiveButtonBg"
android:state_checked="true"/>
</selector>
Then apply it to the checkbox:
ColorStateList darkStateList = ContextCompat.getColorStateList(getContext(), R.color.checkbox_tint_dark_theme); CompoundButtonCompat.setButtonTintList(checkbox, darkStateList);
P.S. In addition if someone is interested, here is how you can get your checkbox from MaterialDialog dialog (if you set it with .checkBoxPromptRes(...)
):
CheckBox checkbox = (CheckBox) dialog.getView().findViewById(R.id.md_promptCheckbox);
Hope this helps.

- 6,256
- 2
- 54
- 42
If textColorSecondary does not work for you, you might have defined colorControlNormal in your theme to be a different color. If so, just use
<style name="yourStyle" parent="Base.Theme.AppCompat">
<item name="colorAccent">your_checked_color</item> <!-- for checked state -->
<item name="colorControlNormal">your_unchecked_color</item> <!-- for unchecked state -->
</style>

- 688
- 8
- 14
Most answers go through the xml file. If you find an active answer for most Android versions and are just one color for the two statuses Check an UnCheck: here is my solution:
Kotlin:
val colorFilter = PorterDuffColorFilter(Color.CYAN, PorterDuff.Mode.SRC_ATOP)
CompoundButtonCompat.getButtonDrawable(checkBox)?.colorFilter = colorFilter
Java:
ColorFilter colorFilter = new PorterDuffColorFilter(Color.CYAN, PorterDuff.Mode.SRC_ATOP);
Drawable drawable = CompoundButtonCompat.getButtonDrawable(checkBox);
if (drawable != null) {
drawable.setColorFilter(colorFilter);
}

- 433
- 3
- 12
You can use the following two properties in "colors.xml"
<color name="colorControlNormal">#eeeeee</color>
<color name="colorControlActivated">#eeeeee</color>
colorControlNormal is for the normal view of checkbox, and colorControlActivated is for when the checkbox is checked.

- 495
- 6
- 18
Hi This is the theme code for both Dark Theme and Light Theme.
<attr name="buttonsearch_picture" format="reference"/>
<attr name="buttonrefresh_picture" format="reference"/>
<style name="Theme.Light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:windowActionBar">false</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:textColorSecondary">@color/black</item>
<item name="android:textColor">@color/material_gray_800</item>
<item name="actionOverflowButtonStyle">@style/LightOverflowButtonStyle</item>
<item name="buttonsearch_picture">@drawable/ic_search_black</item>
<item name="buttonrefresh_picture">@drawable/ic_refresh_black</item>
</style>
<style name="Theme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:windowActionBar">false</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/material_gray_500</item>
<item name="android:textColor">@color/material_gray_800</item>
<item name="actionOverflowButtonStyle">@style/DarkOverflowButtonStyle</item>
<item name="buttonsearch_picture">@drawable/ic_search_white</item>
<item name="buttonrefresh_picture">@drawable/ic_refresh_white</item>
<item name="android:colorBackground">#ffffff</item>
<item name="android:alertDialogTheme">@style/LightDialogTheme</item>
<item name="android:alertDialogStyle">@style/LightDialogTheme</item>
<!-- <item name="android:textViewStyle">@style/AppTheme.Widget.TextView</item>-->
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
If you want to change checkbox color then "colorAccent" attribute will use for checked state and "android:textColorSecondary" will use for unchecking state.
"actionOverflowButtonStyle" will use for change the color of overflow icon in the Action bar.
"buttonsearch_picture" attribute will use for change tint color of Action Button in Action Bar.This is custom Attribute in style.xml
<attr name="buttonsearch_picture" format="reference"/>
Same is for refresh button which i am using in my app.
"android:popupMenuStyle" attribute is using to get Light theme popup menu style in Dark theme.
<style name="PopupMenu" parent="Theme.AppCompat.Light.NoActionBar">
</style>
And this is toolbar Code which I am using in my Rocks Player App.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:contentInsetStart="0dp"
android:title="Rocks Player"
android:layout_width="match_parent"
android:elevation="4dp"
android:layout_height="48dp"
app:layout_scrollFlags="scroll|enterAlways"
android:minHeight="48dp"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary"
>
</android.support.v7.widget.Toolbar>
Themes:-
<style name="AppTheme0" parent="Theme.Light">
<item name="colorPrimary">#ffffff</item>
<item name="colorPrimaryDark">#cccccc</item>
<item name="colorAccent">#0294ff</item>
</style>
<style name="AppTheme1" parent="Theme.Dark">
<item name="colorPrimary">#4161b2</item>
<item name="colorPrimaryDark">#4161b2</item>
<item name="colorAccent">#4161b2</item>
</style>

- 2,328
- 25
- 21
My minSdkVersion is 15
, my BaseAppTheme parent is Theme.AppCompat.Light.NoActionBar
and I am creating my Checkboxes programmatically. The following steps worked for me.
1. In your Java code, change
CheckBox checkBox = new CheckBox(context);
to
AppCompatCheckBox checkBox = new AppCompatCheckBox(context);
2. In your styles.xml, add:
<style name="MyCheckboxStyle" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="buttonTint">@color/primary_dark</item>
</style>
3. Finally, within your BaseAppTheme (or AppTheme) style, add:
<item name="checkboxStyle">@style/MyCheckboxStyle</item>
<item name="android:checkboxStyle">@style/MyCheckboxStyle</item>

- 18,324
- 27
- 171
- 253
You should try below code. It is working for me.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checked"
android:state_checked="true">
<color android:color="@color/yello" />
</item>
<!-- checked -->
<item android:drawable="@drawable/unchecked"
android:state_checked="false">
<color android:color="@color/black"></color>
</item>
<!-- unchecked -->
<item android:drawable="@drawable/checked"
android:state_focused="true">
<color android:color="@color/yello"></color>
</item>
<!-- on focus -->
<item android:drawable="@drawable/unchecked">
<color android:color="@color/black"></color>
</item>
<!-- default -->
</selector>
and CheckBox
<CheckBox
Button="@style/currentcy_check_box_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:text="@string/step_one_currency_aud" />

- 50,076
- 60
- 203
- 339

- 2,037
- 18
- 32
you can create your own xml in drawable and use this as android:background="@drawable/your_xml"
in that you can give border corner everything
<item>
<shape>
<gradient
android:endColor="#fff"
android:startColor="#fff"/>
<corners
android:radius="2dp"/>
<stroke
android:width="15dp"
android:color="#0013669e"/>
</shape>
</item>

- 49
- 3
-
1Whilst it is noice to know about drawable vector graphics this answer does not answer the OP's question about the button tint. – Mike Poole Jan 10 '18 at 07:24
My goal was to use a custom checkbox button and remove the accent color button tint. I tried the accepted answer but did now work instead this worked for me:
In the styles.xml
file
<style name="Theme.Checkbox" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:button">@drawable/theme_checkbox_button</item>
<item name="android:drawableLeft">@android:color/transparent</item>
<item name="android:drawablePadding">10dp</item>
<item name="android:buttonTint">@android:color/transparent</item>
<item name="android:buttonTintMode">screen</item>
</style>
Now for this question, only required attributes are android:buttonTint
and android:buttonTintMode
Now some extras:
- I needed to use a custom drawable, hence
android:button
is set with aselector
drawable - I needed some spacing between the box and the text hence I followed this SO answer and set the
android:drawableLeft
andandroid:drawablePadding

- 520
- 7
- 9
If you are going to use the android icons, as described above ..
android:button="@android:drawable/..."
.. it's a nice option, but for this to work - I found you need to add toggle logic to show/hide the check mark, like this:
checkBoxShowPwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// checkbox status is changed from uncheck to checked.
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int btnDrawable = android.R.drawable.checkbox_off_background;
if (isChecked)
{
btnDrawable = android.R.drawable.checkbox_on_background;
}
checkBoxShowPwd.setButtonDrawable(btnDrawable);
}
});

- 11,284
- 8
- 90
- 137
-
Well, this is extra work that really isn't necessary. In the drawable's xml file you supply references to on or off drawable resources for the selector. This automatically puts the correct drawable according to the checkbox's state. – jkincali Feb 22 '17 at 16:09
You can change the background color of the <CheckBox>
by embedding it inside a <LinearLayout>
. Then change the background color of <LinearLayout>
to the color you want.

- 15,368
- 5
- 42
- 62

- 1,786
- 3
- 15
- 19
I prefer this extension function I've created:
fun CheckBox.setTint(@ColorInt color: Int?) {
if (color == null) {
CompoundButtonCompat.setButtonTintList(this, null)
return
}
CompoundButtonCompat.setButtonTintMode(this, Mode.SRC_ATOP)
CompoundButtonCompat.setButtonTintList(this, ColorStateList.valueOf(color))
}
It's very similar to what I have for ImageView, in case anyone wants it too:
fun ImageView.setTint(@ColorInt color: Int?) {
if (color == null) {
ImageViewCompat.setImageTintList(this, null)
return
}
ImageViewCompat.setImageTintMode(this, Mode.SRC_ATOP)
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(color))
}

- 114,585
- 152
- 739
- 1,270
You can use the below lines of code to change the background of the Checkbox dynamically in your java code.
//Setting up background color on checkbox.
checkbox.setBackgroundColor(Color.parseColor("#00e2a5"));
This answer was from this site. You can also use this site to convert your RGB color to the Hex value, you need to feed the parseColor

- 580
- 1
- 11
- 22

- 17
- 4