1

I would like to use the default checkbox in my app, but I only want the checkbox color to change to red when checked. I tried buttonTint, but it makes the box red when unchecked so that doesn't work.

1

1 Answer 1

2

A relatively easy way to do this would be to apply a theme just to your checkbox. Essentially you would add a style to your styles.xml resource file kind of like the below. Doing it this way you can even give a custom color to your checkbox when it is unchecked. However you can leave off the android:textColorSecondary if you would like to just use the black default checkbox.

styles.xml

//main style above add this below. <style name="RedCheckbox"> <item name="colorAccent">#FF0000</item> //color when checked <item name="android:textColorSecondary>#00FFFF</item> //color when unchecked. </style> 

Then you would need to apply this to your checkbox.

<CheckBox //rest of your checkbox setup android:theme="@style/RedCheckbox" //this is the important line. /> 

You don't need to do anything programmatically it will simply change on the different states. This would be the result:

UNCHECKED

enter image description here

CHECKED

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.