SwitchCompat is a version of the Switch widget that follows Material Design guideline and available in a support library and so working with Android API Level 7+ (Android 2.1 +)
SwitchCompat is a version of the Switch widget, available through the V7 AppCompat library. This library includes support for material design user interface implementations.
To use a SwitchCompat
:
- Add
com.android.support:appcompat-v7:XX.X.X
to your gradle file - Use
<android.support.v7.widget.SwitchCompat ... />
in your layout:
Multiple attributes are available to customize a switch:
app:showText
: Whether to draw on/off textapp:splitTrack
: Whether to split the track and leave a gap for the thumb drawable.app:switchMinWidth
: Minimum width for the switch component May be a dimension value, which is a floating point number appended with a unit such as "14.5sp".app:switchPadding
: Minimum space between the switch and caption text May be a dimension value, which is a floating point number appended with a unit such as "14.5sp".app:switchTextAppearance
: TextAppearance style for text displayed on the switch thumb.app:thumbTextPadding
: Amount of padding on either side of text within the switch thumb.app:thumbTint
: Tint to apply to the thumb drawable.app:thumbTintMode
: Blending mode used to apply the thumb tint.app:track
: Drawable to use as the "track" that the switch thumb slides within.app:trackTint
: Tint to apply to the track.app:trackTintMode
: Blending mode used to apply the track tint.