0

I have few checkbox's at my application with different colors. Now when I applied material design theme checkbox's without style changed their color to "colorControlActivated", checkbox's with style left the same.

Also I wanted to change colors of my other checkbox's without drawables files.

I tried to set style with different "colorControlActivated" color

<style name="CheckBox.Custom" parent="@style/Theme.Material.Blue">
    <item name="colorControlActivated">@color/custom_color</item>
</style>

but it's not working, also I tried to create checkbox like:

ContextThemeWrapper ctw= new ContextThemeWrapper(getActivity(), R.style.CheckBox_Info);
Checkbox cb = new CheckBox(ctw);

and color didn't changed.

The same code working with SwitchCompat control.

Do somebody now how to set different colors to checkbox's without drawables?

Thank you!

Orest
  • 6,548
  • 10
  • 54
  • 84

2 Answers2

0

This did the trick for me. Notice the android namespace.

<style name="CheckBox.Custom" parent="@style/Theme.Material.Blue">
    <item name="android:colorControlActivated">@color/custom_color</item>
</style>
  • android:colorControlActivated requires API level 21 – Orest Jan 08 '15 at 09:29
  • Correct. I assumed that was the platform you were targeting. It seems like Google missed out on supporting 4.x platforms on this since using `colorControlActivated` does not seem to have any effect on the checkbox (as you noticed). Seems like drawables are the only way to go at the moment if you want to change the color (eventually take a look at http://stackoverflow.com/a/27185692/409661). – Peter Haldbæk Jan 10 '15 at 14:59
0

You can set color directly in the xml. Use buttonTint for the box: (as of API level 23)

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:buttonTint="@color/CHECK_COLOR" />

You can also do this using appCompatCheckbox v7 for older APIs:

<android.support.v7.widget.AppCompatCheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:buttonTint="@color/COLOR_HERE" /> 

Add this line in your styles.xml file:

<style>
    <item name="android:colorAccent">@color/custom_color</item>
</style>
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81