0

I am using a switch widget. here is the code

      <Switch
            android:id="@+id/switchFabric"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:showText="true"

           android:switchTextAppearance="@style/SwitchTextAppearance"
            android:text="Do you have fabric ?"
            android:textColor="@color/black_overlay"
            android:textOff="No"
            android:textOn="Yes"
            android:thumbTextPadding="@dimen/padding_4"
            android:padding="@dimen/padding_8"
            android:thumbTint="@color/white"
            android:layout_marginTop="@dimen/margin_10"
            android:layout_marginBottom="@dimen/margin_20"
            />

And it comes out to be this

enter image description here

I want to increase the size of the thumb so that the Yes text has sufficient padding around it. I have tried experimenting with

thumbPadding

padding

switchMinWidth

How to achieve this ? Any suggestions are appreciated. Thanks in advance.

ANUJ GUPTA
  • 905
  • 13
  • 22

2 Answers2

0

try this create theme like this

<style name="MySwitchStyle">
    <item name="android:textColor">#ffffff</item>
    <item name="android:textSize">15sp</item>
</style>

than apply to your switch

 <Switch
        android:id="@+id/switchFabric"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:showText="true"
        android:switchTextAppearance="@style/SwitchTextAppearance"
        android:text="Do you have fabric ?"
        android:textColor="@color/black_overlay"
        android:textOff="No"
        android:textOn="Yes"
        android:scaleX="2"
        android:scaleY="2"
        android:thumbTextPadding="@dimen/padding_4"
        android:padding="@dimen/padding_8"
        android:thumbTint="@color/white"
        app:switchTextAppearance="@style/MySwitchStyle"
        android:layout_marginTop="@dimen/margin_10"
        android:layout_marginBottom="@dimen/margin_20"
        />
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

I think this should do the job it worked for me

<android.support.v7.widget.SwitchCompat
            android:id="@+id/switch_compat2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:checked="true"
            android:scaleX="2"
            android:scaleY="2"
            android:textOn="YES"
            android:textOff="NO"
            app:switchTextAppearance="@style/dd"
            app:showText="true" />

Add the following lines In your styles.xml

  <style name="dd">
        <item name="android:textColor">#ffffff</item>
        <item name="android:textSize">10sp</item>
    </style>

Adjust text size and scale size as per your need