Change the Color of Android Switch (CCAS)

I'm using a standard Switch control with the holo.light theme in an ICS app. I want to change the highlighted or active Toggle Button color from the default light blue to green. This should be easy, but I can't seem to figure out how to do it.

Solution

You need to go into the style.xml file to be able to do this.

 <style  name= "SCBSwitch"  parent= "Theme.AppCompat.Light" > 
        <!-- active thumb & track color (30% transparency) --> 
        <item  name= "colorControlActivated" > #46bdbf </item>

        <!-- inactive thumb color --> 
        <item  name= "colorSwitchThumbNormal" > #f1f1f1
         </item>

        <!-- inactive track color (30% transparency) --> 
        <item  name= "android:colorForeground" > #42221f1f
         </item> 
    </style>

Then implement your theme in the switch component.

<android.support.v7.widget.SwitchCompat 
    android:layout_width= "wrap_content" 
    android:layout_height= "wrap_content" 
    android:layout_alignParentRight= "true" 
    android:checked= "false" 
    android:theme= "@style/SCBSwitch"  />

See the results

Post a Comment

Previous Next

نموذج الاتصال