Android: android:textOn and android:textOff on Switch not working
NickName:zer0stimulus Ask DateTime:2013-03-01T23:39:30

Android: android:textOn and android:textOff on Switch not working

Changing the android:textOn and android:textOff attributes of Switch does not work on my S3. The label on my switch always shows "ON" and "OFF".

Switch Documentation

<Switch
                        xmlns:android="http://schemas.android.com/apk/res/android"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textOn="@string/on"
                        android:textOff="@string/off"
                        android:includeFontPadding="false"/>

Copyright Notice:Content Author:「zer0stimulus」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15161417/android-androidtexton-and-androidtextoff-on-switch-not-working

Answers
Rawkode 2013-03-01T15:53:12

I just tested this on a Samsung Galaxy S3, and it works just fine.\n\nHere's my XML\n\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n tools:context=\".MainActivity\" >\n\n <ToggleButton\n android:id=\"@+id/toggleButton1\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_above=\"@+id/switch1\"\n android:layout_centerHorizontal=\"true\"\n android:layout_marginBottom=\"16dp\"\n android:textOn=\"CHANGEMEON\"\n android:textOff=\"CHANGEMOFF\"\n android:text=\"ToggleButton\" />\n\n</RelativeLayout>\n",


More about “Android: android:textOn and android:textOff on Switch not working” related questions

Android: android:textOn and android:textOff on Switch not working

Changing the android:textOn and android:textOff attributes of Switch does not work on my S3. The label on my switch always shows "ON" and "OFF". Switch Documentation &lt;Switch ...

Show Detail

Android Switch widget textOn and textOff not working as expected

I have a UI where I have added a Switch widget (introduced in API 14). The XML looks like this: &lt;Switch android:id="@+id/togglebutton" android:layout_margin="10dp" android:

Show Detail

Android Switch TextOn/TextOff Placement

I have set the text for my switch, however it is displayed inside the slider like this: How can I get it shown below the switch instead? &lt;android.support.v7.widget.SwitchCompat an...

Show Detail

Android Switch widget textOn and textOff not working in Lollipop

The behavior of the switch widget changed in Lollipop (5.0). &lt;Switch android:id="@+id/switcher" android:layout_width="wrap_content" android:layout_height="0dp"

Show Detail

Change Position of textOn and textOff in Android Swtich

I have implemented the Switch Widget this way: &lt;android.support.v7.widget.SwitchCompat xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"...

Show Detail

Switch widget textOn and textOff text is not appearing in lowercase

Android Switch widget textOn and textOff text is always appearing in uppercase. Is there anyway to change the case without custom xml file? &lt;Switch android:id="@+id/switch1" android:

Show Detail

Android Switch xml textOn string resource

Is there a way to specify a resource id in XML for a Switch? When I do the following I get random integers which I'm assuming are the id itself and not the resolved String? &lt;Switch android:...

Show Detail

Why switch's textOn and textOff are not displaying?

I am trying to make a listview with an on/off switch. I found this simple code but the problem is it is not working for me. &lt;Switch android:id="@+id/itemListSwitch" android:layout_width="

Show Detail

accessibility text for switch view reads as " switch checked" and "switched not checked" if the textOn and textOff is empty

In my application i need to show a switch view with no text , i am using below code. &lt;Switch android:id="@+id/switchsample" android:layout_width="wrap_conten...

Show Detail

android:textColorHighlight for android Switch not working

I need to change the color of both side in android switch button. I tried with android:textColorHighlight in my xml file but it seems not work. This is my code: &lt;Switch androi...

Show Detail