I have an Activity with some radio buttons and checboxes. ATM they look like this:
Now i want to change this greenish accent color to something else. How would be the best way to achive that?
I have an Activity with some radio buttons and checboxes. ATM they look like this:
Now i want to change this greenish accent color to something else. How would be the best way to achive that?
You can use the OnCheckedChangeListener
and one own image for this. For example:
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
checkbox.setButtonDrawable(R.drawable.yourImage);
}
}
});
Use a one-color-image when you want a one-color-background like the green one.
create a checkbox_selector.xml
in your drawable
folder like this, and you need two image normal_checkbox.png
and selected_checkbox.png
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/normal_checkbox"
android:state_checked="false"/>
<item android:drawable="@drawable/selected_checkbox"
android:state_checked="true"/>
<item android:drawable="@drawable/normal_checkbox"/>
</selector>
and now change your layout file where you declare CheckBox
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_selector"
android:text="My CheckBox"
android:textColor="@color/Black" />
for more click
For those looking for this in 2021 and after, now there's a simplier way to accomplish this, using just this little piece of css:
input[type=checkbox], input[type=radio] {
accent-color: #FFCD00;
}