0

I create a Switch button this way:

            Switch sw = new Switch(activity);
            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("OK");
            sw.setTextOff("NOK");
            layout.addView(sw);

The switch appears, but with no text. Furthermore, I want the style to be like as this URL: https://developer.xamarin.com/guides/android/user_interface/form_elements/togglebutton/

How can I achieve all of this? Thanks

EDIT:

I have get this switch button, which is ugly:

enter image description here

jstuardo
  • 3,901
  • 14
  • 61
  • 136

2 Answers2

0

You need to allow the text to be shown:

sw.setShowText(true)

pgiitu
  • 1,671
  • 1
  • 15
  • 23
  • Yes, but I had to increase API Level first. However, the style is very ugly, as shown in the picture I uploaded to the question... is there a way to make it prettier? – jstuardo Oct 20 '15 at 01:56
0

To style your switch, you can see: How to custom switch button?

Maybe you should change the track and thumb drawable

Community
  • 1
  • 1
Raymond Lukanta
  • 495
  • 3
  • 14