我想更改复选框边框颜色的颜色,但我需要以编程方式执行此操作。
这是我的代码
if (Build.VERSION.SDK_INT < 21) {
//The issue is here
CompoundButtonCompat.setButtonTintList(holder.checkbox, ColorStateList.valueOf(this.currentThemeOptions.modalFormsTextColor));
} else {
//This works just fine
holder.checkbox.setButtonTintList(ColorStateList.valueOf(this.currentThemeOptions.modalFormsTextColor));
}
对于更改Android API 低于API 21 的复选框的边框颜色,您有何建议?
答案 0 :(得分:0)
这是我之前用于应用程序的解决方案,它具有可自定义的UI:
AppCompatCheckBox box = new AppCompatCheckBox(activity);
box.setText("Checkbox");
ColorStateList colorStateList = new ColorStateList(
new int[][] {
new int[] { -android.R.attr.state_checked }, // unchecked border color
new int[] { android.R.attr.state_checked } // checked color
},
new int[] {
Color.BLACK,
Color.WHITE
}
);
box.setSupportButtonTintList(colorStateList);
box.setTextColor(Color.BLACK);