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)