Skip to content
Titanium SDK
Version13.2.0

You are reading 13.2.0. See this page in 13.4.1.

Titanium.UI.ActivityIndicator

viewAndroidiPhoneiPadmacOSsince 0.8

Extends Titanium.UI.ViewTitanium.Proxy

An activity indicator that lets the user know an action is taking place.

Android iOS
Android iOS

An activity indicator can be used to show the progress of an operation in the UI to let the user know that some action is taking place. An activity indicator consists of a spinning animation and an optional text message, and is used to indicate an ongoing activity of indeterminate length. To show progress, use Titanium.UI.ProgressBar instead.

Use the Titanium.UI.createActivityIndicator method or <ActivityIndicator> Alloy element to create an ActivityIndicator object.

ActivityIndicator is a view and, like any view, must be added to a window or other top-level view before it can be shown. Unlike most views, ActivityIndicator is hidden by default and must be shown explicitly by calling its Titanium.UI.ActivityIndicator.show method.

Examples

Simple Activity Indicator

Open a yellow window immediately after a blue window. Show an activity indicator while some code executes and hide it on completion. Then close the yellow window.

Ti.UI.backgroundColor = 'white';

var win1 = Ti.UI.createWindow({
  backgroundColor: 'blue'
});

var win2 = Ti.UI.createWindow({
  backgroundColor: 'yellow'
});

var activityIndicator = Ti.UI.createActivityIndicator({
  color: 'green',
  message: 'Loading ...',
  style: Ti.UI.ActivityIndicatorStyle.DARK,
  top: 10,
  left: 10,
  height: Ti.UI.SIZE,
  width: Ti.UI.SIZE
});

// The activity indicator must be added to a window or view for it to appear
win2.add(activityIndicator);

// eventListeners must always be loaded before the event is likely to fire
// hence, the open() method must be positioned before the window is opened
win2.addEventListener('open', function (e) {
  activityIndicator.show();
  // do some work that takes 6 seconds
  // ie. replace the following setTimeout block with your code
  setTimeout(function() {
    e.source.close();
    activityIndicator.hide();
  }, 6000);
});

win1.open();
win2.open();

Alloy XML Markup

Previous example as two Alloy views.

win1.xml:

<Alloy>
    <Window onOpen="openWin2" backgroundColor="blue" />
</Alloy>

win1.js:

function openWin2 () {
    var win2 = Alloy.createController('win2').getView();
    win2.open();
}

win2.xml:

<Alloy>
    <Window onOpen="showIndicator" backgroundColor="yellow">
        <!-- Define the styling properties in the TSS file -->
        <ActivityIndicator id="activityIndicator" message="Loading..."/>
    </Window>
</Alloy>

win2.js:

function showIndicator(e) {
    $.activityIndicator.show();
    // do some work that takes 6 seconds
    // ie. replace the following setTimeout block with your code
    setTimeout(function() {
        e.source.close();
        $.activityIndicator.hide();
    }, 6000);
}

Properties 36

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

bottom

Number | String

Bottom position of the view.

Determines the absolute position of the view relative to its parent.

Can be either a float value or a dimension string (for example 100 or '50%'.)

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

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

Default: true

Color of the message text, as a color name or hex triplet.

For information about color values, see the "Colors" section of Titanium.UI.

elevation

NumberAndroidsince 5.0.0Android 5+

Inherited from Titanium.UI.View

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

Font used for the message text.

height

String

Width of the view. Only accepts value of Titanium.UI.SIZE, which must be explicitly set in order to display the message and to position the view correctly.

Accepts

left

Number | String

Left position of the view.

Determines the absolute position of the view relative to its parent.

Can be either a float value or a dimension string (for example 100 or '50%'.)

messageid

String

Key identifying a string in the locale file to use for the message text.

Only one of message or messageid should be specified.

rotation

NumberAndroidiPhoneiPadsince Android 5.4.0, iPhone 12.3.0, iPad 12.3.0

Inherited from Titanium.UI.View

Clockwise 2D rotation of the view in degrees.

style

Number

The style for the activity indicator.

One of the activity indicator style constants.

See also: indicatorColor

Default: <Titanium.UI.ActivityIndicatorStyle.PLAIN>

tooltip

Stringsince 12.1.0iOS 15.0+

Inherited from Titanium.UI.View

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

top

Number | String

Top position of the view.

Determines the absolute position of the view relative to its parent.

Can be either a float value or a dimension string (for example 100 or'50%'.)

touchFeedback

BooleanAndroidsince 6.1.0

Inherited from Titanium.UI.View

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

Default: false

translationX

NumberAndroidsince 5.0.0

Inherited from Titanium.UI.View

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

width

String

Width of the view. Only accepts value of Titanium.UI.SIZE, which must be explicitly set in order to display the message and to position the view correctly.

Accepts

Methods 10

Inherited from Titanium.Proxy

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

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

getViewById

since 6.1.0

Inherited from Titanium.UI.View

Returns the matching view of a given view ID.

Parameters
ParametersTypeDescription
idString

The ID of the view that should be returned. Use the id property in your views to enable it for indexing in this method.

Hides the activity indicator and stops the animation.

insertAt

since 3.3.0

Inherited from Titanium.UI.View

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

Parameters
ParametersTypeDescription
paramsViewPositionOptions

Pass an object that specifies the view to insert and optionally at which position (defaults to end)

2 fields
position? Number

Position in the children array of the view element to replace.

view Titanium.UI.View

View to insert. Required.

Inherited from Titanium.Proxy

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

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to remove. Must be the same function passed to addEventListener.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Shows the activity indicator and starts the animation.

Remember to add the activity indicator to a parent view first, so it centers properly. This is optional for Android and required for iOS.

Events 1

rotate

since 12.7.0

Inherited from Titanium.UI.View

Fired when the device detects a two finger rotation.

Event properties
Event propertiesTypeDescription
rotateNumber

Rotation in degrees.