R
R
robert_n2017-01-17 03:49:36
Android
robert_n, 2017-01-17 03:49:36

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);

I found the same question on SO , but for some reason it was left without attention. Have you met with such a problem? How can you solve it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rou1997, 2017-01-17
@Rou1997

AppCompat code is there, Android code is there, localize the problem, is it exactly with AppCompatCheckbox, what about others AppCompat*, what about other use cases of the function setSupportButtonTintList, is it exactly the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question