beetlebug

ztk::android::alert

Shows an alert or a list of choices (AlertDialog) over the window, and gives its object at once.

Light Dark
An alert of Android over the Fruit list: the title Delete Plums?, the message Plums leave the list., and the buttons Cancel and Delete in red The same alert in the dark mode of Android

Synopsis

ztk::android::alert ?-title TEXT? ?-message TEXT? ?-style alert|sheet? ?-buttons LIST? ?-command SCRIPT?

Arguments

Name Type Default Meaning
-title text empty The title.
-message text empty The text under the title. A sheet, and an alert of more than two buttons besides cancel, show their buttons as a list in place of the message.
-style alert, sheet alert alert shows the buttons along the bottom of the dialog: the cancel button on the left and the last button on the right. sheet shows the buttons as a list of choices, with the cancel button under them.
-buttons list {OK} The buttons, each one {LABEL ?STYLE?}. STYLE is default, cancel, or destructive. A destructive button or item of a list of choices is red.
-command script empty Runs at the global level at a tap on a button, with the label of the button appended.
buttons method Gives the labels of the buttons, in their order.
invoke INDEX method Closes the alert and runs -command, as a tap on the button INDEX does.
destroy method Frees the alert.

A tap on a button closes the alert, runs -command, and destroys the object. A tap out of the alert does not close it. The alert shows over native screens and over the Tk window. An alert has no configure or cget.

Return value

The command gives the object of the alert. buttons gives a list. invoke gives an empty string.

Errors

Error When
unknown option "-X": must be -buttons, -command, -message, -style, or -title Another option.
value for "-X" missing An option with no value.
bad style "STYLE": must be alert or sheet -style has another value.
bad button style "STYLE": must be cancel, default, or destructive A button has another style.
an alert needs a button -buttons is an empty list.
expected integer but got "X" The index of invoke is no integer.
Android could not make the alert The system did not make the dialog.

Platforms

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

Example

ztk::android::alert -title "Delete Plums?" -message "Plums leave the list." \
    -buttons {{Cancel cancel} {Delete destructive}} \
    -command {apply {{label} {if {$label eq "Delete"} {puts deleted}}}}

See also