1

I need to create the switch as the below image Required

I have both on and off images for it. I implemented them as

   <android.support.v7.widget.SwitchCompat
                    android:id="@+id/swtichTournament"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:showText="false"
                    android:thumb="@drawable/switch_selector"
                    android:layout_centerVertical="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:checked="false" />

The selector XML

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/switch_off" />
<item android:state_pressed="true"  android:drawable="@drawable/switch_on" />
<item android:state_checked="true"  android:drawable="@drawable/switch_on" />
<item                               android:drawable="@drawable/switch_off" />

This is what I get

My OUTPUT

As you can see there is some extra color which is not required. How do I remove that?

WISHY
  • 11,067
  • 25
  • 105
  • 197

3 Answers3

4

If you are using the AppCompat library, replace your switch element by a SwitchCompat element and you'll get what you want. For more info about switchCompat, please see: https://developer.android.com/reference/android/support/v7/widget/SwitchCompat.html

k3v1n4ud3
  • 2,904
  • 1
  • 15
  • 19
2

You can set Switch's background to transparent in your XML:

android:background="@android:color/transparent"
vilpe89
  • 4,656
  • 1
  • 29
  • 36
0

i hope this link will be help you https://androidician.wordpress.com/2014/09/24/android-custom-toggle-button-example-ios-like-toggle-buttons/

Hitesh Singh
  • 1,951
  • 1
  • 10
  • 15