I am creating a switch button programmatically. The problem I have is that the button does not show the ON / OFF
text. This is the creation code:
final RelativeLayout.LayoutParams ll = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
ll.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
sw.setLayoutParams(ll);
sw.setTextOn(values[0].getName());
sw.setTextOff(values[1].getName());
values[0].getName() returns "OK", and values[1].getName() returns "NOK"
What may be going on?
Thanks Jaime
You can do this through XML
<Switch
...
android:showText="true" />
Or Programatically as
mSwitch.setShowText(true);
Here is the answer from Android-API. You have to flag the switch that it can show labels at all!!
public void setShowText (boolean showText) Added in API level 21
Sets whether the on/off text should be displayed.
Related XML Attributes:
android:showText
Parameters showText true to display on/off text
http://developer.android.com/reference/android/widget/Switch.html#setShowText%28boolean%29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With