4

I am trying to change the color of "disabled" state in a SwitchCompat. I added this at Styles.xml:

<style name="SwitchTheme" parent="Theme.AppCompat.Light">
    <item name="android:colorControlActivated">#148E13</item>
    <item name="android:colorSwitchThumbNormal">#FF0000</item>
</style>

When I compile, I get the following error:

error: style attribute 'android:attr/colorSwitchThumbNormal' is private.

If I comment that line, I have no errors, and the app is installed without problem. I have checked this, but I think there are no errors in my xml files, since I would receive an error by commenting that line...I have also no rogue xml files, nor rogue Activities...Have anyone faced this problem? How to fix it, and change my switch disabled color?

Thank you.

Fustigador
  • 6,339
  • 12
  • 59
  • 115
  • Possible duplicate of [cardslib error resource android:attr/foregroundInsidePadding is private while targeting SDK 26](https://stackoverflow.com/questions/45865366/cardslib-error-resource-androidattr-foregroundinsidepadding-is-private-while-ta) – Daniel Beleza Apr 12 '19 at 21:02

1 Answers1

3

Instead of this

<item name="android:colorSwitchThumbNormal">@color/myColor</item>

Try this

<item name="colorSwitchThumbNormal">@color/myColor</item>

For me, this removed the error, but it still didn't apply the color. And in order for that to work, the XML element for the Switch button couldn't be this:

<Switch .... blla blla blla />

But instead, it had to be this XML element:

<android.support.v7.widget.SwitchCompat ..... blla blla blla/>
Albos Hajdari
  • 113
  • 1
  • 12