beetlebug

ztk::android::Switch

Makes an on and off switch (Switch).

Synopsis

ztk::android::Switch new ?OPTION VALUE ...?
$stack add switch ?OPTION VALUE ...?

Arguments

Name Type Default Meaning
-on boolean 0 The state. cget -on gives the state after the taps of the user. A change with configure runs no -command.
-enabled boolean 1 0 dims the switch, and it ignores taps.
-command script empty Runs after the user changes the state, with the switch appended.
invoke method Changes the state and runs -command, as a tap does.
-hidden boolean 0 1 hides the view, and its column or row closes the gap.
-accessibilityLabel text empty The name that TalkBack reads: the content description of the view.
-accessibilityHint text empty Android has no hint for a view: the option keeps its value and has no effect.

Return value

new gives the object. invoke gives an empty string.

Errors

Error When
unknown option "-X": must be ... The class has no such option. The message lists the options.
value for "-X" missing configure has an option with no value.
expected boolean value but got "X" A bad value of -on or -enabled.

Platforms

Platform Works
Windows No
macOS No
Linux, Wayland No
Linux, X11 No
Web No
iOS No: ztk::ios::Switch
Android Yes
Headless No: the namespace does not exist.

Example

set screen [ztk::android::Screen new -title Settings]
set row [$screen add stack -axis horizontal -spacing 12]
$row add label -text "Wi-Fi"
$row add switch -on 1 -command {apply {{sw} {puts [$sw cget -on]}}}
ztk::android::app root $screen

See also