Home > Blockchain >  How do you remove a switch's color or change its on/off color to the same color?
How do you remove a switch's color or change its on/off color to the same color?

Time:10-29

I want to have a switch that switches from 2 different modes, but I can't figure out how to remove the switch color and make on/off the same color. It would be weird if a mode has a different color than another mode. Is this possible and how do you do it?

I've tried using a style that has the same color with colorControlActivated, colorSwitchThumbNormal and android:colorForeground but on/off still had some differences in color

CodePudding user response:

You can use something like:

<style name="Widget.App.Switch" parent="Widget.Material3.CompoundButton.Switch">
    <item name="materialThemeOverlay">@style/ThemeOverlay.App.Switch</item>
</style>

<style name="ThemeOverlay.App.Switch" parent="">
    <!-- thumb colors-->
    <item name="colorPrimary">@color/blu500_light</item> <!--checked-->
    <item name="colorOnSurface">@color/blu500_light</item> <!--unchecked-->

    <!-- track colors-->
    <item name="colorOutline">@color/red500_light</item> <!--unchecked-->
    <item name="colorPrimaryContainer">@color/red500_light</item> <!--checked-->
</style>

and in your layout:

<com.google.android.material.switchmaterial.SwitchMaterial
    style="@style/Widget.App.Switch"

enter image description here enter image description here

  • Related