Skip to content

You are here: Toast API

Toast API

A Toast is a small feedback message that appears for a short time on the screen. Toasts can be used to display informative messages, and they are non-interactive.

The Toast API uses the voltmx.ui Namespace and the following API elements.

voltmx.ui Namespace

Function Description
voltmx.ui.Toast Creates a Toast object.

Toast Object

Method Description
show Displays the toast message on screen.
Property Description
alignConfig Sets the alignment of the toast.
data Provides the information that you want to display in the toast.
isVisible Configures the visibility of a toast.
template Holds a FlexContainer that is used as the template for the custom toast.
widgetDataMap Maps the information between widget IDs and keys in the data.

Using the voltmx.ui.Toast function, you can create a toast object, define the text message that you want to display, and the duration of the toast on the screen.

var toast = new voltmx.ui.Toast({"text": "This is the toast's text.",   
"duration": constants.TOAST_LENGTH_SHORT});;

Use the alignConfig property to set the alignment of the toast object. You can check the visibility of the toast using the isVisible property. To set the text to be displayed on the toast for different widgets, use the data property. Further, you can customize the toast using the template property. If you do not set a template, a default text style is applied to the toast. Configure the widgetDataMap property to update the toast each time there is a change in data. After you configure the properties of the toast, invoke the function to display the toast on the screen.

Important: The Toast API is only available for the Android platform.

Toast Templates

You can use templates to customize the appearance of toasts. To set a template for a toast, assign a FlexContainer widget to the toast object's template property. You can only use the following widgets in the template.

  • Label widget
  • Link widget
  • RichText widget
  • Button widget
  • Image widget

Important: Usage of widgets other than those that are mentioned earlier, would result in undefined behavior.
An image widget with a dynamic URL and widget animations are not supported.

To view the functionality of the Toast API in action, download the sample application from the link below. Once the application is downloaded, build and preview the application using the Volt MX App.