Home » Android » Android themes change checkbox item text color

Android themes change checkbox item text color

Posted by: admin May 14, 2020 Leave a comment

Questions:

How do I just change the text color of checkbox views in Android Studio’s styles.xml?

I want to create a theme where all checkbox items are a color different from the default black like:

enter image description here

Except I want the box itself to be the same color as the text.

Should I be using the following in my theme?

<item name="android:checkboxStyle">@style/App_CheckboxStyle</item>
How to&Answers:

I know that this question is asked long time ago but I want to add my solution. It works with all SDK versions.

You are right that in order to change CheckBox style in the whole project, you have to add the line to your theme:

<style name="AppTheme" parent="Theme.AppCompat">
    ...
    <item name="android:checkboxStyle">@style/MyCheckBoxStyle</item>
    ...
</style>

And the style itself, where you set your custom text and checkbox color:

<style name="MyCheckBoxStyle" parent="Widget.AppCompat.CompoundButton.CheckBox">
    <item name="android:textColor">@android:color/holo_purple</item>
    <item name="buttonTint">@android:color/holo_purple</item>
</style>

Note: android: prefix indicates that a property is linked to SDK attributes. If you remove it, the property links to support library. That’s why system treats buttonTint and android:buttonTint as different parameters. If your minimum SDK is 21, you don’t need to use support library and you can simply use android:buttonTint.

Answer:

You can use android:textColorPrimaryDisableOnly for change CheckBox/RadioButton textColor and colorAccent for change the drawable

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorAccent">#00f</item> <!-- blue -->
    <item name="android:textColorPrimaryDisableOnly">#f00</item> <!-- red -->
</style>

enter image description here

Answer:

You can change the color of the checkbox, using this:

<item name="colorAccent">@color/green</item>

You can change the color of the textView in the checkbox, using this:

<item name="android:textColorSecondary">@color/red</item>

For example:

<style name="SampleTheme" parent="Theme.AppCompat">
    <item name="colorAccent">@color/green</item>
    <item name="android:textColorSecondary">@color/red</item>
</style>

Else, create 3 xml files for customized colors as mentioned in this answer (look where it says Second Method).

Answer:

The solution for me was to use textColor property:

<CheckBox
android:textColor="@color/mycolor"
...
/>

Answer:

You can change color by using drawable like this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" 
        android:drawable="@drawable/cbchk_blue"
        android:state_focused="false">
    </item>
    <item android:state_checked="true" 
        android:drawable="@drawable/cbchk_blue"
        android:state_focused="true">
    </item>
    <item android:state_checked="false" 
        android:drawable="@drawable/cbunchk_blue"
        android:state_focused="false">
    </item>
    <item android:state_checked="false" 
        android:drawable="@drawable/cbunchk_blue"
        android:state_focused="true">
    </item>
</selector>

in you layout just use button property

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/custom_checkbox"
        android:id="@+id/checkBox" />

Answer:

There is no attribute has impact on Checkbox text color at theme level.

All you can do to change text color is to define a style as shown below and apply it to checkbox using style attribute.

<style name="MyChkTextColor">
    <item name="android:textColor">#7ca011</item>4
</style>

http://www.zoftino.com/android-ui-control-checkbox