Class “Switch”

Object > NativeObject > Widget > Switch

A switch widget that can be toggled.

Switch on Android
Android
Switch on iOS
iOS
Type: Switch extends Widget
Constructor: public
Singleton: No
Namespace: tabris
Direct subclasses: None
JSX Support: Element: <Switch/>
Parent Elements: <Canvas/>, <Composite/>, <Page/>, <RefreshComposite/>, <ScrollView/>, <Stack/>, <Tab/>
Child Elements: Not Supported
Text Content: Not supported

Examples

JavaScript

import {Switch, contentView} from 'tabris';

new Switch()
  .onSelect(() => console.log('Switch toggled'))
  .appendTo(contentView);

See also:

JSX Creating a Switch

Constructor

new Switch(properties?)

Parameter Type Description
properties Properties<Switch> Sets all key-value pairs in the properties object as widget properties. Optional.

Properties

checked

The checked state of the switch.

Type: boolean
Default: false
Settable: Yes
Change Event: checkedChanged

thumbOffColor

The color of the movable thumb, when switched off.

Type: ColorValue
Settable: Yes
Change Event: thumbOffColorChanged

thumbOnColor

The color of the movable thumb, when switched on.

Type: ColorValue
Settable: Yes
Change Event: thumbOnColorChanged

trackOffColor

The color of the track that holds the thumb, when switched off.

Type: ColorValue
Settable: Yes
Change Event: trackOffColorChanged

trackOnColor

The color of the track that holds the thumb, when switched on.

Type: ColorValue
Settable: Yes
Change Event: trackOnColorChanged

Events

select

Fired when the switch is toggled by the user.

EventObject Type: SwitchSelectEvent<Switch>

Property Type Description
checked boolean The current value of checked.

Change Events

checkedChanged

Fired when the checked property has changed.

EventObject Type: PropertyChangedEvent<Switch, boolean>

Property Type Description
value boolean The new value of checked.

thumbOnColorChanged

Fired when the thumbOnColor property has changed.

EventObject Type: PropertyChangedEvent<Switch, ColorValue>

Property Type Description
value ColorValue The new value of thumbOnColor.

thumbOffColorChanged

Fired when the thumbOffColor property has changed.

EventObject Type: PropertyChangedEvent<Switch, ColorValue>

Property Type Description
value ColorValue The new value of thumbOffColor.

trackOnColorChanged

Fired when the trackOnColor property has changed.

EventObject Type: PropertyChangedEvent<Switch, ColorValue>

Property Type Description
value ColorValue The new value of trackOnColor.

trackOffColorChanged

Fired when the trackOffColor property has changed.

EventObject Type: PropertyChangedEvent<Switch, ColorValue>

Property Type Description
value ColorValue The new value of trackOffColor.