I created RadioButton
and CheckBox
in LinearLayout
programatically. But, now I want to change radio button\'s color and check boxes\'s
I am continuing the answer of ywwynm.
Google made the setSupportButtonTintList restricted so it is not possible to use it.
The workaround is to use the button as a TintableCompoundButton interface, in which the method is not restricted.
Works in API 19+ for AppCompatRadioButton. AppCompatCheckbox implements the same interface so it should work as well in theory but I haven't tested it.
Have fun :)
public static void setAppCompatRadioButtonColor(AppCompatRadioButton radioButton, int uncheckedColor, int checkedColor) {
ColorStateList colorStateList = new ColorStateList(
new int[][] {
new int[] { -android.R.attr.state_checked }, // unchecked
new int[] { android.R.attr.state_checked } // checked
},
new int[] {
uncheckedColor,
checkedColor
}
);
((TintableCompoundButton) radioButton).setSupportButtonTintList(colorStateList);
}