I'm trying to change the checkbox box's color programmatically to a different color than the theme's default. The problem is I was doing something like this:
checkbox.setSupportButtonTintList(ColorStateList);
It works but it seems, according its class documentation, this method has been restricted to be used only by classes from the same package (com.android.support). This is the warning I got from Android Studio:
AppCompatCheckBox.setSupportButtonTintList can only be called from within the same library group (groupId=com.android.support)
Is there a standard/correct way of doing this for all API levels?
If you want to change checkbox color then "colorAccent" attribute will use for checked state and "android:textColorSecondary" will use for unchecking state. "actionOverflowButtonStyle" will use for change the color of overflow icon in the Action bar. Same is for refresh button which i am using in my app.
If you want to style particular checkbox then create your own style and extend it to @style/Widget. AppCompat. CompoundButton. CheckBox .
Checkboxes allow the user to select one or more options from a set. Typically, you should present each checkbox option in a vertical list. To create each checkbox option, create a CheckBox in your layout.
By default, the android CheckBox will be in the OFF (Unchecked) state. We can change the default state of CheckBox by using android:checked attribute. In case, if we want to change the state of CheckBox to ON (Checked), then we need to set android:checked = “true” in our XML layout file.
Based on rylexr answer, you can specify the color in the following way:
CompoundButtonCompat.setButtonTintList(checkboxView, ColorStateList
.valueOf(getResources().getColor(R.color.red)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With