Skip to content

Titanium.UI.Android.Snackbar

Snackbars provide brief messages about app processes at the bottom of the screen.

Android
Android

For design guidelines, see Material design: Snackbars

Extends: Titanium.UI.View · Since: 11.1.0 · Platforms: android

Properties #

accessibilityDisableLongPress#

extendedcreation only

Type: Boolean

Boolean value to remove the long press notification for the device's accessibility service.

Will disable the "double tap and hold for long press" message when selecting an item.

action#

Type: String

Text of the right hand action button

apiName#

extended

Type: String

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button
returns Ti.UI.Button.

bubbleParent#

extended

Type: Boolean

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often
established by the add() method. For example, for a button added to a window, a
click event on the button would bubble up to the window. Other common parents are
table sections to their rows, table views to their sections, and scrollable views
to their views. Set this property to false to disable the bubbling to the proxy's parent.

elevation#

extended

Type: Number

Base elevation of the view relative to its parent in pixels.

The elevation of a view determines the appearance of its shadow.
Higher elevations produce larger and softer shadows.

Note: The elevation property only works on Titanium.UI.View objects.
Many Android components have a default elevation that cannot be modified.
For more information, see
Google design guidelines: Elevation and shadows.

filterTouchesWhenObscured#

extended

Type: Boolean

Discards touch related events if another app's system overlay covers the view.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a
system overlay to intercept touch events in your app or to trick the end-user to tap on UI
in your app intended for the overlay.

Setting this property to true causes touch related events (including "click") to not be fired
if a system overlay overlaps the view.

hiddenBehavior#

extended

Type: Number

Sets the behavior when hiding an object to release or keep the free space

If setting hiddenBehavior to Titanium.UI.HIDDEN_BEHAVIOR_GONE it will automatically release the space the view occupied.
For example: in a vertical layout the views below the object will move up when you hide
an object with hiddenBehavior:Titanium.UI.HIDDEN_BEHAVIOR_GONE.

Defaults to Titanium.UI.HIDDEN_BEHAVIOR_INVISIBLE.

horizontalMotionEffect#

extended

Type: MinMaxOptions

Adds a horizontal parallax effect to the view

Note that the parallax effect only happens by tilting the device so results can not be seen on Simulator.
To clear all motion effects, use the Titanium.UI.clearMotionEffects method.

id#

extended

Type: String

View's identifier.

The id property of the Ti.UI.View represents the view's identifier. The identifier string does
not have to be unique. You can use this property with Titanium.UI.View.getViewById method.

keepHardwareMode#

extended

Type: Boolean

A value indicating the render mode of the View

Set to true to keep hardware mode when using a border and transparent backgrounds.

length#

Type: Number

Display time of the Snackbar

Use with on of the constants: Ti.UI.Android.Snackbar.LENGTH_SHORT,
Ti.UI.Android.Snackbar.LENGTH_LONG or
Ti.UI.Android.Snackbar.LENGTH_INDEFINITE

LENGTH_INDEFINITE#

Type: Number

Use with length to specify the display time.

LENGTH_LONG#

Type: Number

Use with length to specify the display time.

LENGTH_SHORT#

Type: Number

Use with length to specify the display time.

lifecycleContainer#

extended

Type: Titanium.UI.Window, Titanium.UI.TabGroup

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks
will also be called on the proxy. Proxies that require the activity lifecycle will need this property set
to the appropriate containing Window or TabGroup.

message#

Type: String

Text of Snackbar

previewContext#

extended

Type: Titanium.UI.iOS.PreviewContext

The preview context used in the 3D-Touch feature "Peek and Pop".

Preview context to present the "Peek and Pop" of a view. Use an configured instance
of Titanium.UI.iOS.PreviewContext here.

Note: This property can only be used on devices running iOS 9 or later and supporting 3D-Touch.
It is ignored on older devices and can manually be checked using Titanium.UI.iOS.forceTouchSupported.

rotation#

extended

Type: Number

Clockwise 2D rotation of the view in degrees.

Translation values are applied to the static post layout value.

rotationX#

extended

Type: Number

Clockwise rotation of the view in degrees (x-axis).

Translation values are applied to the static post layout value.

rotationY#

extended

Type: Number

Clockwise rotation of the view in degrees (y-axis).

Translation values are applied to the static post layout value.

scaleX#

extended

Type: Number

Scaling of the view in x-axis in pixels.

Translation values are applied to the static post layout value.

scaleY#

extended

Type: Number

Scaling of the view in y-axis in pixels.

Translation values are applied to the static post layout value.

tooltip#

extended

Type: String

The default text to display in the control's tooltip.

Assigning a value to this property causes the tool tip to be displayed for the view.
Setting the property to null cancels the display of the tool tip for the view.
Note: This property is only used for apps targeting macOS Catalyst.

touchFeedback#

extended

Type: Boolean

A material design visual construct that provides an instantaneous visual confirmation of touch point.

Touch feedback is only applied to a view's background. It is never applied to the view's foreground content
such as a Titanium.UI.ImageView's image.

For Titanium versions older than 9.1.0, touch feedback only works if you set the
Titanium.UI.View.backgroundColor property to a non-transparent color.

touchFeedbackColor#

extended

Type: String

Optional touch feedback ripple color. This has no effect unless touchFeedback is true.

Defaults to provided theme color.

transitionName#

extended

Type: String

A name to identify this view in activity transition.

Name should be unique in the View hierarchy.

translationX#

extended

Type: Number

Horizontal location of the view relative to its left position in pixels.

Translation values are applied to the static post layout value.

translationY#

extended

Type: Number

Vertical location of the view relative to its top position in pixels.

Translation values are applied to the static post layout value.

translationZ#

extended

Type: Number

Depth of the view relative to its elevation in pixels.

Translation values are applied to the static post layout value.

verticalMotionEffect#

extended

Type: MinMaxOptions

Adds a vertical parallax effect to the view

Note that the parallax effect only happens by tilting the device so results can not be seen on Simulator.
To clear all motion effects, use the Titanium.UI.clearMotionEffects method.

Methods #

addEventListener #

extended

Adds the specified callback as an event listener for the named event.

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to invoke when the event is fired.No

applyProperties #

extended

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that
myproxy[key] = value.

Parameters:
NameTypeSummaryOptional
propsDictionaryA dictionary of properties to apply.No

clearMotionEffects #

extended

Removes all previously added motion effects.

fireEvent #

extended

Fires a synthesized event to any registered listeners.

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
eventDictionaryA dictionary of keys and values to add to the Titanium.Event object sent to the listeners.Yes

getViewById #

extended

Returns the matching view of a given view ID.

Parameters:
NameTypeSummaryOptional
idStringThe ID of the view that should be returned. Use the id property in your views to
enable it for indexing in this method.
No

Returns: Titanium.UI.View

hide #

extended

Hides this view.

Parameters:
NameTypeSummaryOptional
optionsAnimatedOptionsAnimation options for Android only. Since SDK 5.1.0 and used only on Android 5.0+

Determines whether to enable a circular reveal animation.
Note that the default here is equivalent to passing in { animated: false }
Yes

insertAt #

extended

Inserts a view at the specified position in the children array.

Useful if the layout property is set to horizontal or vertical.

Parameters:
NameTypeSummaryOptional
paramsViewPositionOptionsPass an object that specifies the view to insert and optionally at which position (defaults to end)
No

removeEventListener #

extended

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the
callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function
in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);
Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to remove. Must be the same function passed to addEventListener.No

replaceAt #

extended

Replaces a view at the specified position in the children array.

Useful if the layout property is set to horizontal or vertical.

Parameters:
NameTypeSummaryOptional
paramsViewPositionOptionsPass an object with the view to insert and the position of the view to replace. In this case the position property is required.
No

show #

Show the Snackbar

stopAnimation #

extended

Stops a running animation.

Stops a running view Animation.

Events #

click #

Fired when the action button is clicked

Event Properties:
NameTypeSummary
actionStringThe text of the action button.

rotate #

extended

Fired when the device detects a two finger rotation.

This event is fired when doing a two finger rotation and returning the angle.
The event occurs continuously until a finger is lifted again.

Event Properties:
NameTypeSummary
rotateNumberRotation in degrees.

Examples #

Show a Snackbar

Display a Snackbar with an action button.

const win = Ti.UI.createWindow();
const btn = Ti.UI.createButton({
  title: 'show message'
});
btn.addEventListener('click', function() {
  snack.show();
});

const snack = Ti.UI.Android.createSnackbar({
  message: 'Hello Snackbar!',
  length: Ti.UI.Android.Snackbar.LENGTH_INDEFINITE,
  action: 'click me'
});
snack.addEventListener('click', function(e) {
  console.log(e.action);
});

win.add([btn, snack]);
win.open();

Titanium SDK Documentation