2

So far I have managed to customize a switch from xml following instructions based on this stackoverflow question. However, I need to set thumb/track drawables programmatically.

Documentation on Android Switch class, makes it clear that the following methods

setThumbResource(int)
setThumbTextPadding(int)
setTrackResource(int)

will only work on android API level 16 and above. Is it feasible to achieve the same results, i.e. set thumb resource programmatically for API levels 14 and 15? If yes, how?

Community
  • 1
  • 1
kouretinho
  • 2,190
  • 1
  • 23
  • 37
  • can you put different seekbars each one with a different thumb and hide one or another as you need them? or you must change the thumb on the same seekbar? – Dante May 21 '14 at 17:14
  • lol, I really don't get what you mean by the different seekbars. Can you point me to any kind of code sample to get a better idea? – kouretinho May 21 '14 at 17:58
  • Sorry, its an idea i got with your problem. What i meant is you putting several seekbars on the layout each one with a different thumb and invisible with only one of them visible. So if you need to change the thumb you'd just hide the visible seekbar and show the one that has the thumb you need. Do you get my idea? Sry, english is not my mother's tongue – Dante May 21 '14 at 18:26

1 Answers1

0

If you wish to set the drawable resources programatically, you can use the class android.support.v7.widget.SwitchCompat instead of the default android.widget.Switch. The former provides the methods you mentioned down to API level 7.

DPR
  • 770
  • 1
  • 11
  • 29