问题
I found a very strange behaviour in my AppCompatCheckBox, already searched a fix for it but didn't find, that's why I decided to ask here.
I was trying to change the checked AppCompatCheckBox color programatically (as my app's color scheme changes dinamically, I can't use the XML attributes to color the CheckBox), so I used this approach:
chkTos = (AppCompatCheckBox) findViewById(R.id.checkboxTos);
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked},
},
new int[]{
Color.DKGRAY,
Color.RED,
}
);
chkTos.setSupportButtonTintList(colorStateList);
it worked, the checked color is now red, but the animation is now VERY SLOW. The performance is terrible! How can I fix this?
Have you experienced anything like this? I wanted to show you it in action, will try to create a gif of it! Maybe this is a bug on the support library?
Some references:
Change Circle color of radio button- Android
How to change checkbox checked color programmatically
回答1:
For anyone still struggling with this bug, instead of setting the SupportButtonTintList
you have to set the ButtonTintList
with the colorStateList
you want. So the code will be like:
chkTos.setButtonTintList(colorStateList);
来源:https://stackoverflow.com/questions/37488550/how-to-change-appcompatcheckbox-color-efficiently