Answer the question
In order to leave comments, you need to log in
How to programmatically change the color of AppCompatCheckbox?
Hello! There was a need to change the color of controls depending on the selected values in the application settings. Those. I need to change the color programmatically, not with styles.
The problem primarily arose with the AppCompatCheckBox. The fact is that on Lollilop 5.1 API 22 devices, the checkbox color always remains gray. No matter what I do, nothing changes. And on versions below and above 22, everything works well. Here is the code I am using:
@BindView(R.id.checkbox)
AppCompatCheckBox checkbox;
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{-android.R.attr.state_checked}
},
new int[] {
item.colorIcon, // checked
ContextCompat.getColor(context, R.color.divider) // unchecked
}
);
checkbox.setSupportButtonTintList(colorStateList);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question