Skip to content Skip to sidebar Skip to footer

Removing Whitespace In Android Switch Which Is Devoted To Text

(we all know) There are three parts in android Switch Widget ... Text - Thumb - Track. My question is how can we completely remove this text part if we don't want to use any text

Solution 1:

You simply have to not provide any text:

    <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

Solution 2:

Use negative margin for the switch as follows and see if it works:

 <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-10dp" />

I know some people consider it a bad practice to use negative margin but right it seems to be the easiest way.

You can set margin programmatically as well based on device type.

Post a Comment for "Removing Whitespace In Android Switch Which Is Devoted To Text"