StatusBar

Extends Widget

The status bar is the area where notifications, status icons and device time are displayed. The singleton instance can be accessed via ui.statusBar.

Import this type with “const {StatusBar} = require('tabris');

Properties

background

Type: Color

Background color of the status bar. Should be used in conjunction with the theme property to keep the status bar icons legible.

displayMode

Type: string, supported values: default, hide, float, default: default

Controls how the status bar is positioned relative to the ui.contentView. The value default places the content below the status bar. The hide option lets the status bar disappear, making more room for the content. The float option lets the content flow underneath the status bar. On Windows float is currently not supported and treated as hide.

height

read-only Type: number

The height of the status bar in device independent pixel. Can be used in conjunction with the displayMode 'float' to offset the content as to not have it covered by the status bar.This property can only be set on widget creation. Once set, it cannot be changed anymore.

theme

iOSAndroid

Type: string, supported values: default, light, dark, default: default

Defines the shade used on the status bar. A dark theme sets the foreground icons to be of a light color, whereas light sets the icons to a dark color. The theme should be set in conjunction with the background property for contrast. The value default selects the default theme that depends on the device and on the app. Available on iOS and Android 6+.

Events

backgroundChanged

Fired when the background property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: Color The new value of background.

displayModeChanged

Fired when the displayMode property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: string The new value of displayMode.

themeChanged

Fired when the theme property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: string The new value of theme.

Example

  1. const {Picker, TextView, ui} = require('tabris');
  2. const THEMES = ['default', 'light', 'dark'];
  3. const DISPLAY_MODES = ['default', 'float', 'hide'];
  4. const BACKGROUNDS = [ui.statusBar.background, 'rgba(0, 0, 0, 0.25)', 'red', 'green', 'blue'];
  5. createTextView('Theme', 'theme');
  6. createTextView('Display mode', 'displayMode');
  7. createTextView('Background', 'background');
  8. createTextView('Height', 'height');
  9. new Picker({
  10. left: '#displayMode 16', baseline: '#theme', right: 16,
  11. itemCount: THEMES.length,
  12. itemText: index => THEMES[index]
  13. }).on('select', ({index}) => ui.statusBar.theme = THEMES[index])
  14. .appendTo(ui.contentView);
  15. new Picker({
  16. left: '#displayMode 16', baseline: '#displayMode', right: 16,
  17. itemCount: DISPLAY_MODES.length,
  18. itemText: index => DISPLAY_MODES[index]
  19. }).on('select', ({index}) => ui.statusBar.displayMode = DISPLAY_MODES[index])
  20. .appendTo(ui.contentView);
  21. new Picker({
  22. left: '#displayMode 16', baseline: '#background', right: 16,
  23. itemCount: BACKGROUNDS.length,
  24. itemText: index => BACKGROUNDS[index]
  25. }).on('select', ({index}) => ui.statusBar.background = BACKGROUNDS[index])
  26. .appendTo(ui.contentView);
  27. new TextView({
  28. left: '#displayMode 16', baseline: '#height', right: 16,
  29. text: ui.statusBar.height
  30. }).appendTo(ui.contentView);
  31. function createTextView(text, id) {
  32. new TextView({
  33. id: id,
  34. left: 16, top: 'prev() 16',
  35. text: text
  36. }).appendTo(ui.contentView);
  37. }

See also

原文:

https://youjingyu.github.io/Tabris-Documention/?folderName=widgets&pageName=StatusBar.html