I have been trying to find resources explaining how I can style the Switch button in the Material Design theme.
This link does explain the color values and aesthetic details but doesn't say much on how I can achieve this by setting certain attributes in Material design theme.
http://www.google.com/design/spec/components/switches.html#switches-switch
If there's no direct way of setting the Switch's color, where are the drawables located that I can use to make my own version?
Coloring widgets is pretty simple now with the new appcompat-v7:21.
As long as you are using appcompat-v7:21, you can replace all of your old
Switchwidgets withSwitchCompatwidgets. So in your xml layouts, instead of using the oldSwitchtag, useandroid.support.v7.widget.SwitchCompat.Then in your styles.xml, make sure your app's parent theme is a
Theme.AppCompattheme such asTheme.AppCompat.Light.Finally, the key is to specify your own value for
colorAccent:The color you specify for
colorAccentwill be used to color the widgets in your app such asSwitchCompats,EditTexts,RadioButtons, etc.So your styles.xml might look something like:
I wouldn't recommend altering the drawables directly, but they are located in
sdk/platforms/android-21/data/res/drawable-XXXXand the files are called
btn_switch_to_off_mtrl_XXXXX.9.png
btn_switch_to_on_mtrl_XXXXX.9.png
switch_track_mtrl_alpha.9.png