Button

Extends Widget

A push button. Can contain a text or an image.

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

Android iOS
Button on Android Button on iOS

Properties

alignment

Type: string, supported values: left, right, center, default: center

The horizontal alignment of the button text.

image

Type: Image

An image to be displayed on the button.

text

Type: string

The button’s label text.

textColor

Type: Color

The color of the text.

Events

alignmentChanged

Fired when the alignment property has changed.

Event Parameters

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

  • value: string The new value of alignment.

imageChanged

Fired when the image property has changed.

Event Parameters

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

  • value: Image The new value of image.

select

Fired when the button is pressed.

textChanged

Fired when the text property has changed.

Event Parameters

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

  • value: string The new value of text.

textColorChanged

Fired when the textColor property has changed.

Event Parameters

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

  • value: Color The new value of textColor.

Example

  1. const {Button, ui} = require('tabris');
  2. // Create a push button that counts up on selection
  3. let count = 0;
  4. new Button({
  5. left: 10, top: 10,
  6. text: 'Button'
  7. }).on('select', ({target}) => target.text = 'Pressed ' + (++count) + ' times')
  8. .appendTo(ui.contentView);

See also

原文:

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