titaniumappceleratorappcelerator-mobileappcelerator-studio

How to set the color to a switch in appcelerator?


I tried with On tint color, color, tint color to change the color of the switch. It isn't working either way.


Solution

  • For Android you can use this theme to set a track and thumb tint color:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <style name="MyThemeActionbar" parent="Theme.AppCompat">
            <!-- switch -->
            <item name="switchStyle">@style/newSwitchStyle</item>
        </style>
    
    
        <style name="newSwitchStyle" parent="android:Widget.CompoundButton">
            <item name="track">@drawable/abc_switch_track_mtrl_alpha</item>
            <item name="android:thumb">@drawable/abc_switch_thumb_material</item>
            <item name="switchTextAppearance">@style/TextAppearance.AppCompat.Widget.Switch</item>
            <item name="android:background">?attr/controlBackground</item>
            <item name="showText">false</item>
            <item name="switchPadding">@dimen/abc_switch_padding</item>
            <item name="android:textOn">@string/abc_capital_on</item>
            <item name="android:textOff">@string/abc_capital_off</item>
    
            <!-- track and button -->
            <item name="trackTint">#00f</item>
            <item name="thumbTint">#f00</item>
        </style>
    </resources>
    
    
    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application android:theme="@style/Theme.MyThemeActionbar"/>
        </manifest>
    </android>
    

    Check: http://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes for applying/adding a theme