Manu Zi
Manu Zi

Reputation: 2370

Customized switch toggle button

I wan't to customized my switch in android. The problem is that the default button overlay my own drawable.

What have i done:

  1. create my own graphics (2 graphics)
  2. create a xml in the drawable folder, that's look like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/switch_female" android:state_checked="false"/>
    <item android:drawable="@drawable/switch_male" android:state_checked="true"/>
</selector>
  1. and my switch definition looks like this:
<Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textOff=""
            android:textOn=""
            android:id="@+id/genderSwitchOne"
            android:layout_below="@+id/txtViewPersonGender"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="25dp"
            android:background="@drawable/gender_switch"/>

but what i get is this:

myswitchbutton

it's possible to remove the default button (over the "em" from female)?

Thanks in advance.

PS: sorry but i can not paste the android xml without blockquote it.

Upvotes: 0

Views: 3418

Answers (1)

Eugen Pechanec
Eugen Pechanec

Reputation: 38223

Set android:thumb="@null" on the Switch XML element. This will erase the thumb drawable from display.

EDIT: As the above produced an NPE, android:thumb="@android:color/transparent" should do the trick as this will get loaded as an actual ColorDrawable.

Upvotes: 1

Related Questions