public class SwitchCompat
extends CompoundButton implements EmojiCompatConfigurationView

   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.Button
         ↳ android.widget.CompoundButton
           ↳ androidx.appcompat.widget.SwitchCompat

SwitchCompat is a complete backport of the core Switch widget that brings the visuals and the functionality of that widget to older versions of the platform. Unlike other widgets in this package, SwitchCompat is not automatically used in layouts that use the <Switch> element. Instead, you need to explicitly use <androidx.appcompat.widget.SwitchCompat> and the matching attributes in your layouts.

A Switch is a two-state toggle switch widget that can be used to select one of the two available options. The user may drag the "thumb" back and forth to choose the selected option, or simply tap to toggle as if it were a checkbox. The text property controls the text displayed in the label for the switch, whereas the off and on text controls the text on the thumb. Similarly, the textAppearance and the related setTypeface() methods control the typeface and style of label text, whereas the switchTextAppearance and the related setSwitchTypeface() methods control that of the thumb.

The thumb can be tinted with setThumbTintList(ColorStateList) and setThumbTintMode(PorterDuff.Mode) APIs, as well as with the matching XML attributes. The track can be tinted with setTrackTintList(ColorStateList) and setTrackTintMode(PorterDuff.Mode) APIs, as well as with the matching XML attributes.

See the Toggle Buttons guide.

R.attr.textOn R.attr.textOff R.attr.switchMinWidth R.attr.switchPadding R.attr.switchTextAppearance R.attr.thumb R.attr.thumbTextPadding R.attr.track R.attr.thumbTint R.attr.thumbTintMode R.attr.trackTint R.attr.trackTintMode


Inherited constants