An activity indicator that lets the user know an action is taking place.
![]() |
![]() |
![]() |
Android | iOS | Windows Phone |
---|
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 show method.
Prior to SDK 3.0, activity indicator on Android produced a modal dialog containing a spinner or progress bar. In SDK 3.0, this legacy Android activity indicator was renamed to Titanium.UI.Android.ProgressIndicator.
In SDK 3.0, use ActivityIndicator
for a view that can be added as a child of another view.
Use ProgressIndicator
to display a progress indicator in a modal dialog or window title bar.
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',
fullscreen: true
});
var activityIndicator = Ti.UI.createActivityIndicator({
color: 'green',
font: {fontFamily:'Helvetica Neue', fontSize:26, fontWeight:'bold'},
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();
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" fullscreen="true" 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);
}
The name of the API that this proxy corresponds to.
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
.
Bottom position of the view.
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%'
.)
Overrides: Titanium.UI.View.bottom
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.
Default: true
Color of the message text, as a color name or hex triplet.
Color of the message text, as a color name or hex triplet.
For information about color values, see the "Colors" section of Titanium.UI.
Base elevation of the view relative to its parent in pixels.
Requires: Android 5 and later
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.
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.
Defaults to: If undefined, defaults to either Titanium.UI.FILL or Titanium.UI.SIZE depending on the view. See "View Types and Default Layout Behavior" in Transitioning to the New UI Layout System.
Can be either a float value or a dimension string (for example, '50%' or '40dp'). Can also be one of the following special values:
SIZE
or
FILL
constants if it is necessary to set the view's behavior explicitly.This is an input property for specifying the view's height dimension. To determine the view's size once rendered, use the rect or size properties.
This API can be assigned the following constants:
Overrides: Titanium.UI.View.height
Color of the animated indicator.
Default:
#fff
Left position of the view.
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%'
.)
Overrides: Titanium.UI.View.left
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
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.
Key identifying a string in the locale file to use for the message text.
Key identifying a string in the locale file to use for the message text.
Only one of message
or messageid
should be specified.
The preview context used in the 3D-Touch feature "Peek and Pop".
Requires: iOS 9.0 and later
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 iOS9 or later and supporting 3D-Touch. It is ignored on older devices and can manually be checked using Titanium.UI.iOS.forceTouchSupported.
Right position of the view.
Right 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%'
.)
Overrides: Titanium.UI.View.right
Clockwise 2D rotation of the view in degrees.
Clockwise 2D rotation of the view in degrees.
Translation values are applied to the static post layout value.
Clockwise rotation of the view in degrees (x-axis).
Clockwise rotation of the view in degrees (x-axis).
Translation values are applied to the static post layout value.
Clockwise rotation of the view in degrees (y-axis).
Clockwise rotation of the view in degrees (y-axis).
Translation values are applied to the static post layout value.
Scaling of the view in x-axis in pixels.
Scaling of the view in x-axis in pixels.
Translation values are applied to the static post layout value.
Scaling of the view in y-axis in pixels.
Scaling of the view in y-axis in pixels.
Translation values are applied to the static post layout value.
The style for the activity indicator.
One of the activity indicator style constants.
See also: indicatorColor, indicatorDiameter
This API can be assigned the following constants:
Top position of the view.
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%'
.)
Overrides: Titanium.UI.View.top
A material design visual construct that provides an instantaneous visual confirmation of touch point.
Requires: Android 5.0 and later
This is an opt-in feature available from Android Lollipop. Touch feedback is applied only if the backgroundColor is a solid color.
Default: false
Optional touch feedback ripple color. This has no effect unless touchFeedback
is true.
Requires: Android 5.0 and later
Default: Theme provided color.
A name to identify this view in activity transition.
Requires: Android 5 and later
Name should be unique in the View hierarchy.
Horizontal location of the view relative to its left position in pixels.
Horizontal location of the view relative to its left position in pixels.
Translation values are applied to the static post layout value.
Vertical location of the view relative to its top position in pixels.
Vertical location of the view relative to its top position in pixels.
Translation values are applied to the static post layout value.
Depth of the view relative to its elevation in pixels.
Requires: Android 5 and later
Translation values are applied to the static post layout value.
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.
Defaults to: If undefined, defaults to either Titanium.UI.FILL or Titanium.UI.SIZE depending on the view. See "View Types and Default Layout Behavior" in Transitioning to the New UI Layout System.
Can be either a float value or a dimension string (for example, '50%' or '40dp'). Can also be one of the following special values:
SIZE
or
FILL
constants if it is necessary to set the view's behavior explicitly.This is an input property for specifying the view's width dimension. To determine the view's size once rendered, use the rect or size properties.
This API can be assigned the following constants:
Overrides: Titanium.UI.View.width
Adds a child to this activity indicator's hierarchy.
Adding children to an ActivityIndicator
is not supported on all platforms.
If you need to display views on top of this object, consider using another view as a container for both this object and the views you want to appear on top of it.
See also: Titanium.UI.View.add.
View to add to this view's hierarchy.
You may pass an array of views, e.g. view.add([subview1, subview2]
.
Overrides: Titanium.UI.View.add
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
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.
A dictionary of properties to apply.
Finishes a batch update of the View's layout properties and schedules a layout pass of the view tree.
deprecated since 3.0.0
Use the <Titanium.Proxy.applyProperties> method to batch-update layout properties.
Since the layout pass scheduled is asynchronous, the rect
and size values may not be available immediately after
finishLayout
is called.
To be notified when the layout pass completes, add a listener for the postlayout event.
Fires a synthesized event to any registered listeners.
Name of the event.
A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.
Gets the value of the bottom property.
Overrides: Titanium.UI.View.getBottom
Gets the value of the left property.
Overrides: Titanium.UI.View.getLeft
Gets the value of the right property.
Overrides: Titanium.UI.View.getRight
Gets the value of the top property.
Overrides: Titanium.UI.View.getTop
Returns the matching view of a given view ID.
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.
Animation options for Android. Since Release 5.1.0.
Overrides: Titanium.UI.View.hide
Inserts a view at the specified position in the children array.
Useful if the layout
property is set to horizontal
or vertical
.
Pass an object with the following key-value pairs:
view
(Titanium.UI.View): View to insertposition
(Number): Position in the children array to
insert the view. If omitted, inserts the view to the end of the array.Removes a child from this activity indicator's hierarchy.
Adding children to an ActivityIndicator
is not supported on all platforms.
See also: add, Titanium.UI.View.add.
View to remove from this view's hierarchy.
Overrides: Titanium.UI.View.remove
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);
Name of the event.
Callback function to remove. Must be the same function passed to addEventListener
.
Replaces a view at the specified position in the children array.
Useful if the layout
property is set to horizontal
or vertical
.
Pass an object with the following key-value pairs:
view
(Titanium.UI.View): View to insertposition
(Number): Position in the children array of
the view elment to replace.Sets the value of the bottom property.
New value for the property.
Overrides: Titanium.UI.View.setBottom
Sets the value of the bubbleParent property.
New value for the property.
Sets the value of the color property.
New value for the property.
Sets the value of the elevation property.
New value for the property.
Sets the value of the height property.
New value for the property.
Overrides: Titanium.UI.View.setHeight
Sets the value of the hiddenBehavior property.
New value for the property.
Sets the value of the indicatorColor property.
New value for the property.
Sets the value of the left property.
New value for the property.
Overrides: Titanium.UI.View.setLeft
Sets the value of the lifecycleContainer property.
New value for the property.
Sets the value of the message property.
New value for the property.
Sets the value of the messageid property.
New value for the property.
Sets the value of the previewContext property.
New value for the property.
Sets the value of the right property.
New value for the property.
Overrides: Titanium.UI.View.setRight
Sets the value of the rotation property.
New value for the property.
Sets the value of the rotationX property.
New value for the property.
Sets the value of the rotationY property.
New value for the property.
Sets the value of the scaleX property.
New value for the property.
Sets the value of the scaleY property.
New value for the property.
Sets the value of the style property.
New value for the property.
Sets the value of the top property.
New value for the property.
Overrides: Titanium.UI.View.setTop
Sets the value of the touchFeedback property.
New value for the property.
Sets the value of the touchFeedbackColor property.
New value for the property.
Sets the value of the transitionName property.
New value for the property.
Sets the value of the translationX property.
New value for the property.
Sets the value of the translationY property.
New value for the property.
Sets the value of the translationZ property.
New value for the property.
Sets the value of the width property.
New value for the property.
Overrides: Titanium.UI.View.setWidth
Shows the activity indicator and starts the animation.
Animation options for Android. Since Release 5.1.0.
Overrides: Titanium.UI.View.show
Starts a batch update of this view's layout properties.
deprecated since 3.0.0
Use the <Titanium.Proxy.applyProperties> method to batch-update layout properties.
To prevent a layout pass each time a property is modified, call startLayout
before
changing any properties that may change this view's layout. This initiates a batch update
mode where layout changes are deferred.
Call finishLayout to end batch update mode and trigger a layout pass. For example:
view.startLayout();
view.top = 50;
view.left = 50;
view.finishLayout();
Note that any property changes made during the batch update may be deferred until
finishLayout
is called. This may vary somewhat by platform. For example, changing the
text of a label may trigger a layout pass. In iOS, updating the label text is
deferred.
See also: updateLayout, finishLayout, postlayout event.
Performs a batch update of all supplied layout properties and schedules a layout pass after they have been updated.
deprecated since 3.0.0
Use the <Titanium.Proxy.applyProperties> method to batch-update layout properties.
This is another way to perform a batch update. The updateLayout
method is called with a
dictionary of layout properties to perform the batch update. For example:
view.updateLayout({top:50, left:50});
This is equivalent to the following:
view.startLayout();
view.top = 50;
view.left = 50;
view.finishLayout();
See also: startLayout, finishLayout, postlayout event.
Layout properties to be updated.