Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change the color of Switch

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 7.23k
    Comment on it

    In android, switch is the toggle widget that has two states to select two options.

    User can simply click to toggle or drag back and forth to select the option.

    Here, I am changing the ON color of the SwitchCompat. SwitchCompat is the version of Switch provided in V7.


    I apply a custom theme to the SwitchCompat through theme property

      android:theme="@style/Theme.ToogleTheme"

     

    Below is the code:

    <android.support.v7.widget.SwitchCompat
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:theme="@style/Theme.ToogleTheme"
        android:layout_marginTop="5dp"
        />


     

      <style name="Theme.ToogleTheme" parent="Theme.AppCompat.Light">
            <!-- colorPrimary is used for the default action bar background -->
            <item name="colorPrimary">@color/colorPrimary</item>
    
            <!-- colorPrimaryDark is used for the status bar -->
            <item name="colorPrimaryDark">@color/colorPrimary</item>
    
            <!-- colorAccent is used as the default value for colorControlActivated,
                 which is used to tint widgets -->
            <item name="colorAccent">@color/colorPrimary</item>
    
            <!-- You can also set colorControlNormal, colorControlActivated
                 colorControlHighlight, and colorSwitchThumbNormal. -->
    
        </style>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: