beetlebug

ztk::android

Makes the views of the Android framework from a script: screens, lists, a navigation stack, tabs, alerts, and controls.

The classes, options, and methods are those of ztk::ios in the namespace ztk::android. Each object is a TclOO object. A -command script runs at the global level with the object appended, and an error in it goes to bgerror.

Synopsis

ztk::android::app root ?OBJECT?
ztk::android::alert ?OPTION VALUE ...?
ztk::android::CLASS new ?ARG ...?
$OBJECT METHOD ?ARG ...?

Arguments

Name Type Default Meaning
ztk::android::app command Shows a screen, a navigation stack, or a tab screen over the Tk window.
ztk::android::alert command Shows an alert or a list of choices (AlertDialog), and gives its object.
ztk::android::NavigationStack class A stack of screens with a Toolbar and a back arrow.
ztk::android::Screen class A page with a column of views (ScrollView and LinearLayout).
ztk::android::ListScreen class A page of rows in sections (ListView).
ztk::android::TabScreen class Tabs with a tab bar at the bottom.
ztk::android::Label class A text (TextView).
ztk::android::Button class A button (Button).
ztk::android::Switch class An on and off switch (Switch).
ztk::android::DatePicker class A picker of a date, a time, or both (DatePicker, TimePicker).
ztk::android::TextField class A field of one line of text (EditText).
ztk::android::TextView class A text of many lines (EditText).
ztk::android::Stack class A row or a column of views (LinearLayout).
configure ?OPTION VALUE ...? method Sets options. With one option, gives {OPTION DEFAULT VALUE}. With no argument, gives that list for each option.
cget OPTION method Gives the value of an option. For the text of a text field and the state of a switch, it gives the value on the screen.
destroy method Frees the object and its view. A screen frees the controls of its add calls, and a navigation stack frees its screens.
-hidden boolean 0 Label, button, switch, text field, text view, stack: 1 hides the view, and its column or row closes the gap.
-accessibilityLabel text empty Label, button, switch, text field, text view, stack: the name that TalkBack reads: the content description of the view.
-accessibilityHint text empty Label, button, switch, text field, text view, stack: Android has no hint for a view: the option keeps its value and has no effect.

Return value

new gives the name of the new object. configure with values, and destroy, give 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 boolean option has another value.
bad kind "tkscreen": must be ... ztk::android::TkScreen: the class exists, and the backend of Android has no Tk screen.
bad kind "photos": must be ... ztk::android::photos: the command exists, and the backend of Android has no photo picker yet.
invalid command name "ztk::android::..." The program is not an app on Android.

Platforms

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

Example

if {[namespace exists ztk::android]} {
    set screen [ztk::android::Screen new -title Hello]
    $screen add label -text "A screen of Android."
    $screen add button -text "Tap me" -command {puts tapped}
    ztk::android::app root [ztk::android::NavigationStack new $screen]
}

See also