Define a custom style (theme) on an Android Switch component Define a custom style (theme) on an Android Switch component xml xml

Define a custom style (theme) on an Android Switch component


This post describes what you need: http://www.materialdoc.com/switch/

If the coloring doesn't work (api < 21), take a look atthis stackoverflow post.

Hope this helps you !


As a first step, I suggest you to replace actionBarSherlock with support.v7.app.ActionBar. (https://developer.android.com/reference/android/support/v7/app/ActionBar.html)

This migration needs some time because you must redefine your existing styling. In my memory, when I have made a similar migration, the code of v7 styling looks like actionBarSherlock styling. At this time, v7 ActionBar was named ActionBarCompat.


You can try this:

  • Make an image for the background of your switch.
  • That must have a height equal to that of your circle.
  • And the top and the bottom of the image must look like this:

http://screenshot.sh/owpTUNk8jTtUl