1

I wanted to implement an Switch widget in my app and the function works perfectly. The issue I have with the switch is the off text ("OFF") on the thumb. "OFF" is bigger than the size of the thumb. I want to increase the size of the thumb (or decrease the thumb text), but for some odd reason I am unable to do either. Here is what is looks like:

Close up of the switch

enter image description here

Screen Shot

enter image description here

Here's the XML file:

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/gameSettingsContainer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    tools:context="com.example.vb1115.multchoicequestion.LaunchScreen">
    <LinearLayout
        android:id="@+id/lessonModeSliderContainer"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">
        <Switch
            android:id="@+id/lessonModeToggleSlider"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:showText="true"/>
    </LinearLayout>
    <ImageView
        android:id="@+id/lessonModeAnimatedArrow"
        android:src="@mipmap/green_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/lessonModeSliderContainer"/>
</RelativeLayout>

I don't think there is an issue from the code itself. All I am doing in my Activity code is finding the Switch view to modify the setOnCheckedChangeListener method.

Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
Vik
  • 23
  • 8
  • check this post http://stackoverflow.com/questions/36364153/cant-change-the-textsize-of-the-thumb-of-switchcompat-widget/36418921#36418921 – Bharatesh Apr 12 '16 at 11:23

1 Answers1

0

You can try setting android:textSize on your Switch tag like this :

    <Switch
        android:id="@+id/lessonModeToggleSlider"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textSize="text_size_here" <----- this line
        android:showText="true"/>

The Switch class extends CompoundButton, which extends Button, which extends TextView, making this possible. You can also try using setTextSize() method on your code to set the text size programatically.

reidzeibel
  • 1,622
  • 1
  • 19
  • 24
  • I tried the following: XML: android:textSize="2.0sp" android:textSize="2dp" Code: lessonModeToggle.setTextSize(2.0f); None of the 3 worked... – Vik Feb 17 '16 at 16:20