问题描述
我在AppCompatCheckBox中发现了一个非常奇怪的行为,已经在搜索了修复程序,但是没有找到,这就是为什么我决定在这里询问的原因.
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.
我试图以编程方式更改选中的AppCompatCheckBox颜色(由于我的应用的配色方案发生了动态变化,因此我无法使用XML属性为CheckBox着色),所以我使用了这种方法:
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?
您经历过类似的经历吗?我想向您展示它的作用,将尝试创建它的gif文件!也许这是支持库中的错误?
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?
一些参考文献:
推荐答案
对于仍在努力解决此错误的任何人,不必设置 SupportButtonTintList
,而必须设置 ButtonTintList
与所需的 colorStateList
一起使用.因此,代码将类似于:
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);
这篇关于如何有效地更改AppCompatCheckBox的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!