How do I change the default color of the Android checkbox from green checkmarks to blue for a particular CheckBox?
Unfortunately, changing the colour isn't a simple attribute. The checkmark is an image, so you have to create a custom image. Take a look at this example
Create a selector xml file such as this:
<?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/star_down" />
<item android:state_checked="false" android:drawable="@drawable/star" />
</selector>
save this xml file in your res\drawables\
folder. Then inside your layout file apply it to your checkBox like this:
<CheckBox
android:text="Custom CheckBox"
android:button="@drawable/checkbox_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
In this example you'd name your selector xml file "checkbox_selector.xml" and you'd need a star_down.png, and star.png in your drawables folder as well. You can use this technique to create different colored checkboxes by altering the system checkbox images to whatever color you want and referencing the altered png files in a selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With