0

OK, I don't need nor want AppCompat stuff. This is for a ROM utility app, so I know exactly what API is supported (I literally control the whole system). I don't need anything below API 22 and I'm compiling to that API.

I want to know what I can add to my styles.xml to get the switch color to match the rest of the theme (@color/primary_color). Here is what I have ... (and some of this is likely un-necessary from testing too much at once).

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
        <item name="android:colorButtonNormal">@color/primary_color</item>
        <item name="android:shadowColor">@android:color/black</item>
        <item name="android:colorControlHighlight">@color/primary_color</item>
        <item name="android:textViewStyle">@style/BlackText</item>
        <item name="android:actionMenuTextColor">@color/hilight_color</item>
        <item name="android:colorControlActivated">@color/primary_color</item>
        <item name="android:colorPrimary">@color/blackness</item>
        <item name="android:colorAccent">@color/primary_color</item>
    </style>
    <style name="BlackText">
        <item name="android:textColor">@android:color/black</item>
    </style>
</resources>
Evan Langlois
  • 4,050
  • 2
  • 20
  • 18

1 Answers1

1

In xml layout:

 <android.support.v7.widget.SwitchCompat
            android:id="@+id/switch_subs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:button="@null"
            android:padding="20dp"
            android:theme="@style/ColorSwitchStyle" />

In styles.xml

 <style name="ColorSwitchStyle">
    <item name="colorControlActivated">@color/colorPrimary</item>
 </style>

sample

*** in my case colorPrimary is blue.

Vishal Raj
  • 1,755
  • 2
  • 16
  • 35
  • I don't want to use Compat libraries. I did attempt to try this, and changed the code that references this from Switch to SwitchCompat, added the library dependency. It crashes "Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference" in StaticLayout called from SwitchCompat a couple layers deep, and my own calls aren't even in the backtrace. Is it really this hard? – Evan Langlois Dec 15 '15 at 18:34