Alexey Markov Alexey Markov - 5 months ago 90
Android Question

android - styling checkbox and radiobutton

I am trying to style my app and make own theme, but I faced with some problems, becouse I need some unusial behaviour.

I use Material Design theme with parent

Theme.AppCompat.Light.DarkActionBar


Overview



Views has colors:


  • Text is
    textColorPrimary
    ,
    textColorSecondary
    ,
    textColorTertiary

  • Button is unknown gray color

  • Button text is
    textColorPrimary
    (?)

  • Checkbox and radiobutton unchecked border is
    textColorSecondary

  • Checkbox, radiobutton, sliders etc colors is
    colorAccent



But I need


  • Buttons have
    accentColor
    background and white text

  • All text (
    textColorPrimary
    ,
    textColorSecondary
    ,
    textColorTertiary
    ) is a variants of dark green

  • Checkbox, radiobuttons should be primary color when checked and unchecked too.



My styles



Button



So, I create style
Button.Default


<style name="Button.Default" parent="Widget.AppCompat.Button">
<item name="colorButtonNormal">@color/colorAccent</item>
<item name="android:textColor">@android:color/white</item>
</style>


and use It in my theme:

<item name="android:buttonStyle">@style/Button.Default</item>


OK, color changed, but background didn't. I add this line to the theme style:

<item name="colorButtonNormal">@color/colorFakeAccent</item>


OK

Checkbox



<style name="Checkbox.Default" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:textColor">@color/colorPrimary</item>
<item name="colorAccent">@color/colorPrimary</item>
</style>


And checkbox style didn't change. How can I set checkbox, radiobutton unchecked and checked color?

Answer

Use <item name="colorControlNormal"> <item name="colorControlActivated"> for change color of checkbox