0

Im working on an app which has an Activity containing a PreferenceFragment. When i add a Switch to my fragment, the base color of the switch is pure black, making it hard to see on a Dark theme.

enter image description here

Is it possible to change color of both states of the switch? If so, how?

styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowBackground">@color/colorPrimaryDark</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorPrimary</item>
        <item name="android:navigationBarColor">@color/colorSecondaryDark</item>
        <item name="android:listDivider">@color/colorUnselected</item>
        <item name="colorControlNormal">@android:color/white</item>
        <item name="colorControlActivated">@color/colorSelected</item>
        <item name="colorControlHighlight">@color/colorSecondaryDark</item>
        <item name="popupMenuStyle">@style/popupMenuThemeDark</item>
    </style>

    <style name="popupMenuThemeDark">
        <item name="android:backgroundTint">@color/colorSecondaryDark</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

    <style name="NavigationDrawerTheme">
        <item name="android:listDivider">@color/colorUnselected</item>
    </style>

    <style name="PreferenceScreen" parent="AppTheme">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:colorAccent">@color/colorSelected</item>
    </style>
</resources>
Meltix
  • 436
  • 6
  • 22
  • 1
    Check out the answers to this post and let me know if it answers your question: https://stackoverflow.com/questions/10118050/how-can-i-style-an-android-switch – TofferJ Sep 09 '20 at 20:23
  • Yes, this does answer my question. Feel free to sign this question as duplicate of that one. Thanks for linking! – Meltix Sep 09 '20 at 20:33

0 Answers0