A UI component that displays a two-state button that the user can toggle. Use the Interface clicked block to handle clicks. See Android documentation.
Note! This feature requires Android 12+.
| Attribute | Value type | Description |
|---|---|---|
android:showText | boolean | Whether to draw on/off text. |
android:splitTrack | boolean | Whether to split the track and leave a gap for the thumb. |
android:switchMinWidth | enum | Minimum width for the switch component. |
android:switchPadding | dimension | Space between the switch and caption text. |
android:textOff | string | Text used when the switch is in the unchecked/off state. |
android:textOn | string | Text used when the switch is in the checked/on state. |
android:thumb | drawable | Image used as the thumb that switches back and forth. (Android 6+) |
android:thumbTextPadding | dimension | Padding on either side of text within the switch thumb. |
android:thumbTint | color | Tint of the thumb. (Android 12+) |
android:thumbTintMode | enum | Blending mode of thumb tint:
add, multiply, screen, src_atop, src_in or src_over. (Android 12+) |
android:track | drawable | Image used as the track that the thumb slides within. (Android 6+) |
android:trackTint | color | Tint of the track. (Android 12+) |
android:trackTintMode | enum | lending mode of thumb tint:
add, multiply, screen, src_atop, src_in or src_over. (Android 12+) |
| Attribute | Value type | Description |
|---|---|---|
android:button | drawable | Image used for the button. (Android 6+) |
android:buttonTint | color | Tint of the button drawable. (Android 6+) |
android:buttonTintMode | enum | Blending mode of button tint:
add, multiply, screen, src_atop, src_in or src_over. (Android 10+) |
android:checked | boolean | Whether the button should be in the checked/on state. |
| Attribute | Value type | Description |
|---|---|---|
android:autoLink | boolean | Whether URLs and email addresses in the text are automatically converted to clickable links. |
android:cursorVisible | boolean | Whether cursor/caret is visible. |
android:drawablePadding | dimension | Space between the compound drawables and the text. |
android:ems | integer | Makes the view be exactly this many ems wide. |
android:enabled | boolean | Whether the widget is enabled. |
android:fontFeatureSettings | string | Font feature settings, in the same format as the CSS font-feature-settings. (Android 5+) |
android:fontVariationSettings | string | TrueType or OpenType font variation settings. (Android 8+) |
android:freezesText | boolean | Whether the view includes its current text in its saved state. |
android:gravity | enum | Alignment of the text within the view:
bottom, center, center_horizontal, end, fill, fill_horizontal, fill_vertical, left, right, start and top. |
android:height | dimension | Makes the view be exactly this tall. |
android:hint | string | Text to display when the text is empty. |
android:justificationMode | enum | Mode for justification:
inter_character, inter_word or none. (Android 8+) |
android:letterSpacing | float | Text letter-spacing. (Android 5+) |
android:lineHeight | dimension | Explicit line height for the view. (Android 9+) |
android:lines | integer | Makes the view be exactly this many lines tall. |
android:linksClickable | boolean | Whether links should be clickable. |
android:maxEms | integer | Makes the view be at least this many ems wide. |
android:maxHeight | dimension | Makes the view be at most this many pixels tall. |
android:maxLines | integer | Makes the view be at most this many lines tall. |
android:maxWidth | dimension | Makes the view be at least this many pixels wide. |
android:minEms | integer | Makes the view be at least this many ems wide. |
android:minHeight | dimension | Makes the view be at least this tall. |
android:minLines | integer | Makes the view be at least this many lines tall. |
android:minWidth | dimension | Makes the view be at least this wide. |
android:selectAllOnFocus | boolean | Whether to select all text when the view takes focus, if the text is selectable. |
android:singleLine | boolean | Whether to constrain the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines. |
android:text | string | Text to display. |
android:textAllCaps | boolean | Present the text in ALL CAPS, maybe as small-caps when available. |
android:textColor | color | Text color. |
android:textColorHighlight | color | Color of the text selection highlight. |
android:textColorHint | color | Color of the hint text. |
android:textColorLink | color | Text color for links. |
android:textScaleX | float | Horizontal scaling factor for the text. |
android:textSelectHandle | drawable | Image used as anchor when positioning the cursor when selecting. URIs not supported.(Android 10+) |
android:textSelectHandleLeft | drawable | Image used as the left handle when selecting. URIs not supported. (Android 10+) |
android:textSelectHandleRight | drawable | Image used as the right handle when selecting. URIs not supported. (Android 10+) |
android:textSize | dimension | Size of the text, preferably in the sp unit. |
android:width | dimension | Makes the view be exactly this wide. |
| Attribute | Value type | Description |
|---|---|---|
android:accessibilityTraversalAfter | id | Id of view that screen readers are requested to visit before this view. (Android 5.1+) |
android:accessibilityTraversalBefore | id | Id of a view that screen readers are requested to visit after this view. (Android 5.1+) |
android:alpha | float | Opacity of the view, a decimal value between 0 and 1. |
android:background | color or drawable | Background of the view. URIs not supported. |
android:backgroundTint | color | Tint of the background drawable (Android 12+) |
android:backgroundTintMode | enum | Blending mode of foreground drawable tint:
add, multiply, screen, src_atop, src_in or src_over. (Android 12+) |
android:clickable | boolean | Whether this view reacts to click events. |
android:clipToOutline | boolean | Whether to use the views’ outline clip its contents. |
android:contentDescription | string | Brief description of the view content, primarily for accessibility. |
android:elevation | dimension | Base elevation of the view, often shown as a drop shadow. (Android 5+) |
android:focusable | enum | Whether the view can take input focus:
true, false or auto. |
android:focusableInTouchMode | boolean | Whether the view can take input focus while in touch mode. |
android:focusedByDefault | boolean | Whether the view is a default-focus view. (Android 8+) |
android:foregroundGravity | flags | Gravity of the foreground drawable:
bottom, center, center_horizontal, center_vertical, fill, fill_horizontal, fill_vertical, left, right and top. (Android 6+) |
android:foregroundTint | enum | Tint of the foreground drawable. (Android 12+) |
android:foregroundTintMode | enum | Blending mode of foreground drawable tint:
add, multiply, screen, src_atop, src_in or src_over. (Android 12+) |
android:id | id | Identifier name for this view. |
android:labelFor | id | Id of a view for which this view serves as a label for. (Android 4.2+) |
android:layoutDirection | enum | Direction of layout drawing, usually associated with writing direction of the language:
inherit, locale, ltr or rtl (Android 4.2+) |
android:layout_gravity | enum | Position of children within their bounds:
bottom, center, center_horizontal, center_vertical, fill, fill_horizontal, fill_vertical, left, right and top. (Android 6+) |
android:layout_height | enum or dimension | Height of the view:
match_parent or wrap_content, using a dimension requires Android 12+. |
android:layout_margin | dimension | Extra space outside the edges of the view. (Android 12+) |
android:layout_marginBottom | dimension | Extra space outside the bottom edge of the view. (Android 12+) |
android:layout_marginEnd | dimension | Extra space outside the end edge of the view. (Android 12+) |
android:layout_marginHorizontal | dimension | Extra space outside the left and right edge of the view. (Android 12+) |
android:layout_marginLeft | dimension | Extra space outside the left edge of the view. (Android 12+) |
android:layout_marginRight | dimension | Extra space outside the right edge of the view. (Android 12+) |
android:layout_marginStart | dimension | Extra space outside the start edge of the view. (Android 12+) |
android:layout_marginTop | dimension | Extra space outside the top edge of the view. (Android 12+) |
android:layout_marginVertical | dimension | Extra space outside the top and bottom edge of the view. (Android 12+) |
android:layout_weight | integer | How extra space is allocated to the view. An integer between 0 (stretch) and 5. |
android:layout_width | enum or dimension | Width of the view:
match_parent, wrap_content, or on Android 12+ a dimension. |
android:minHeight | dimension | Minimum height of the view. |
android:minWidth | dimension | Minimum width of the view. |
android:outlineRadius | dimension | Corner radius of view outline, see android:clipToOutline. (Android 12+) |
android:padding | dimension | Extra space around the view. (Android 12+) |
android:paddingBottom | dimension | Extra space between the content bottom side and the view edge. (Android 12+) |
android:paddingLeft | dimension | Extra space between the content left side and the view edge. (Android 12+) |
android:paddingRight | dimension | Extra space between the content right side and the view edge. (Android 12+) |
android:paddingTop | dimension | Extra space between the content top side and the of the view edge. (Android 12+) |
android:rotation | float | Rotation of the view, in degrees. |
android:rotationX | float | Rotation of the view around the horizontal axis, in degrees. |
android:rotationY | float | Rotation of the view around the vertical axis, in degrees. |
android:scaleX | float | Horizontal scale of the view. |
android:scaleY | float | Vertical scale of the view. |
android:scrollIndicators | enum | Scroll indicators to show, if scrolling is allowed:
bottom, end, left, none, right, start or top. |
android:supplementalDescription | string | Brief supplemental information for the view, primarily for accessibility. (Android 16+) |
android:transformPivotX | float | Horizontal point around which the view will rotate and scale. |
android:transformPivotY | float | Vertical point around which the view will rotate and scale. |
android:translationX | float | Horizontal translation of the view. |
android:translationY | float | Vertical translation of the view. |
android:translationZ | float | Elevation depth translation of the view. |
android:visibility | enum | Visibility of the view:
gone, invisible or visible. |