Android Guides | Samples

Android.Widget.Switch Class

A Switch is a two-state toggle switch widget that can select between two options.

See Also: Switch

Syntax

[Android.Runtime.Register("android/widget/Switch", DoNotGenerateAcw=true)]
public class Switch : CompoundButton

Remarks

A Switch is a two-state toggle switch widget that can select between two 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 TextView.TextFormatted property controls the text displayed in the label for the switch, whereas the Switch.TextOffFormatted and Switch.TextOnFormatted text controls the text on the thumb. Similarly, the TextView.SetTextAppearance(Context,Int32) and the related setTypeface() methods control the typeface and style of label text, whereas the Switch.SetSwitchTextAppearance(Context,Int32) and the related setSwitchTypeface() methods control that of the thumb.

See the Toggle Buttons guide.

[Android Documentation]

Requirements

Namespace: Android.Widget
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 14

The members of Android.Widget.Switch are listed below.

See Also: CompoundButton

Public Constructors

Construct a new Switch with default styling.
Construct a new Switch with default styling, overriding specific style attributes as requested.
Construct a new Switch with a default style determined by the given theme attribute, overriding specific style attributes as requested.
Construct a new Switch with a default style determined by the given theme attribute or style resource, overriding specific style attributes as requested.

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

ShowTextBoolean.
SplitTrackBoolean. Returns whether the track should be split by the thumb.
SwitchMinWidthInt32. Get the minimum width of the switch in pixels.
SwitchPaddingInt32. Get the amount of horizontal padding between the switch and the associated text.
TextOffString.
TextOffFormattedICharSequence. Returns the text displayed when the button is not in the checked state.
TextOnString.
TextOnFormattedICharSequence. Returns the text displayed when the button is in the checked state.
ThumbDrawableDrawable. Get the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.
ThumbTextPaddingInt32. Get the horizontal padding around the text drawn on the switch itself.
TrackDrawableDrawable. Get the drawable used for the track that the switch slides within.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

OnMeasure(Int32, Int32)
SetSwitchTextAppearance(Context, Int32)
Sets the switch text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
SetSwitchTypeface(Typeface)
Sets the typeface in which the text should be displayed on the switch.
SetSwitchTypeface(Typeface, TypefaceStyle)
Sets the typeface and style in which the text should be displayed on the switch, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.
SetThumbResource(Int32)
Set the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.
SetTrackResource(Int32)
Set the drawable used for the track that the switch slides within.