Class “Switch”

Object > NativeObject > Widget > Switch

A switch widget that can be toggled.

Switch on Android
Android
Switch on iOS
iOS
Constructor public
Singleton No
Namespace tabris
Direct subclasses None
JSX support Element: <Switch/>
Parent element: <Composite/> and any widget extending Composite
Child elements: None
Text content: Not supported

Example

import {Switch, contentView} from 'tabris';

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

Constructor

new Switch(properties?)

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

Properties

checked

The checked state of the switch.

Type boolean
Default false
Settable Yes

thumbOffColor

The color of the movable thumb, when switched off.

Type ColorValue
Settable Yes

thumbOnColor

The color of the movable thumb, when switched on.

Type ColorValue
Settable Yes

trackOffColor

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

Type ColorValue
Settable Yes

trackOnColor

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

Type ColorValue
Settable Yes

Events

select

Fired when the switch is toggled by the user.

Parameter Type Description
checked boolean The current value of checked.

Change Events

checkedChanged

Fired when the checked property has changed.

Parameter Type Description
value boolean The new value of checked.

thumbOnColorChanged

Fired when the thumbOnColor property has changed.

Parameter Type Description
value ColorValue The new value of thumbOnColor.

thumbOffColorChanged

Fired when the thumbOffColor property has changed.

Parameter Type Description
value ColorValue The new value of thumbOffColor.

trackOnColorChanged

Fired when the trackOnColor property has changed.

Parameter Type Description
value ColorValue The new value of trackOnColor.

trackOffColorChanged

Fired when the trackOffColor property has changed.

Parameter Type Description
value ColorValue The new value of trackOffColor.