0

I'm using the following code to programmatically create a switch:

Switch s = new Switch(mActivity);

s.setText(text);
s.setBackground(selectorDrawable);       
s.setTypeface(mFont);
s.setTextSize(mEntriesTextSize);
s.setTextSize(8);
s.setTag(command);
s.setVisibility(View.VISIBLE);
s.setPadding(mEntriesSidesPadding,
    mEntriesUpDownPadding, mEntriesSidesPadding,
    mEntriesUpDownPadding);
s.setChecked(on);

// attempted to change height here...

s.setOnCheckedChangeListener(mOnCheckedListener);

mLayout.addView(s, mLayoutParams);
returnView = s;

How might I go about changing the height of the actual switch on screen (not the text height, the height of the ON/OFF switch itself)

I've tried

setMaxHeight(), setMinHeight(), setHeight()

but nothing seems to work.

Gaëtan Maisse
  • 12,208
  • 9
  • 44
  • 47

2 Answers2

0

You can use:

s.getLayoutParams().height = YOUR_HEIGHT;

(YOUR_HEIGHT is desired height in pixel)

If you're setting the height after the layout has already been 'laid out', make sure you call:

s.requestLayout()
Gaëtan Maisse
  • 12,208
  • 9
  • 44
  • 47
0

The solution which worked best was:

            s.setSwitchMinWidth(x);

where x is your desired value. Took me a while to find this amongst said similar functions.