Titanium.Android.ActionBar
> Titanium.Android.ActionBar

An action bar is a window feature that identifies the application and user location, and provides user actions and navigation modes.

Starting with Release 3.3.0, the Titanium SDK uses the appcompat library to provide support for the action bar, including devices running Android 2.3.x and prior. If you are using a release earlier than 3.3.0, refer to the Applicaton Note below for additional information.

You can add action items to the action bar by defining an Android menu and setting the menu items to display as action items. See Menu and MenuItem for details.

In JavaScript, wait for the window or tab group's open event before accessing the action bar from the window or tab group's activity.

Note that setting the Window.navBarHidden property to true disables the Action Bar since it is part of the navigation title bar.

For more examples on using the Action Bar, refer to the Android Action Bar guide.

Application Notes for Alloy

Starting with Alloy 1.5.0, you can add ActionBar attributes to the ActionBar element. To use the action bar, add the <ActionBar> tag as a child of either a a <Window> or <TabGroup>, then set ActionBar attributes in either the XML or TSS file.

Starting with Alloy 1.4.0, you can also add ActionBar attributes to the Menu element. Do not define ActionBar attributes in both the ActionBar and Menu elements. Only define the attributes in one element.

To add action items to the action bar, add the <Menu> tag as a child of either a <Window> or <TabGroup>, then add <MenuItem> tags as children of the <Menu> tag. Set MenuItem attributes in either the XML or TSS file.

For an example of using the Action Bar with Alloy, see "Action Bar using Alloy XML Markup" below.

Action Bar Icon

Starting with Release 4.0, due to the requirement that the target SDK must be set to Android 5.0 (API level 21) or higher, the action bar icon may not display. Google is discouraging the use of icons in toolbars:

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars
than on their application icon. The use of application icon plus title as a standard layout is
discouraged on API 21 devices and newer.

Source: Android Developer: Toolbar API reference

Application Note for Release 3.2.x and earlier

If you are using Release 3.2.x or earlier, this feature is only available in Android 3.0 (API level 11) and above.

To access the action bar, you must first open a heavyweight window or tab group that uses one of the action bar themes (such as the Android Holo theme).

Examples

Action Bar using Alloy XML Markup

Adds action items and sets several properties on a window's action bar in the XML and TSS files.

app/views/index.xml:

<Alloy>
    <Window title="My Test App">
        <ActionBar id="actionbar" title="My XML Menu" onHomeIconItemSelected="doMenuClick" />
        <Menu>
            <MenuItem id="item1" title="Settings" onClick="openSettings" />
            <MenuItem id="item2" title="Search" onClick="doSearch" />
        </Menu>
        <Label id="label">Welcome!</Label>
    </Window>
</Alloy>

app/styles/index.tss:

"MenuItem": {
    showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS
},
"#item1": {
    icon: Ti.Android.R.drawable.ic_menu_preferences
},
"#item2": {
    icon: Ti.Android.R.drawable.ic_menu_search
},
"#actionbar": {
    icon: "/actionicon.png",
    displayHomeAsUp: true,
    backgroundImage: "/actionbackground.png"
}

Action Bar Example

The following example sets several properties on a window's action bar.

var win = Ti.UI.createWindow({
    title: "Old Title",
    navBarHidden: false
});
var actionBar;

win.addEventListener("open", function() {
    if (Ti.Platform.osname === "android") {
        if (! win.activity) {
            Ti.API.error("Can't access action bar on a lightweight window.");
        } else {
            actionBar = win.activity.actionBar;
            if (actionBar) {
                actionBar.backgroundImage = "/bg.png";
                actionBar.title = "New Title";
                actionBar.onHomeIconItemSelected = function() {
                    Ti.API.info("Home icon clicked!");
                };
            }
        }
    }
});

win.open();

Nearly identical code can be used for a tab group, but in Release 3.0, the tab group's activity must be accessed using the getActivity method.

  • 3.0
Defined By

Properties

apiName : Stringreadonly

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.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Titanium.Android.ActionBar
backgroundImage : Stringwriteonly

The background image for the action bar, specified as a local file path or URL.

The background image for the action bar, specified as a local file path or URL.

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

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

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.Android.ActionBar
customView : Titanium.UI.View

Sets a view to be used for a custom navigation mode.

Sets a view to be used for a custom navigation mode.

Inserts a custom view for navigation in the space between the application's home button and menu actions. The custom view is trimmed to fit the space available.

  • 7.1.0
Titanium.Android.ActionBar
displayHomeAsUp : Booleanwriteonly

Displays an "up" affordance on the "home" area of the action bar.

Displays an "up" affordance on the "home" area of the action bar.

See also: setDisplayHomeAsUpEnabled in the Android Developer Reference.

Titanium.Android.ActionBar
homeButtonEnabled : Booleanwriteonly

Enable or disable the "home" button in the corner of the action bar.

Enable or disable the "home" button in the corner of the action bar.

See also: setHomeButtonEnabled in the Android Developer Reference.

  • 3.3.0
Titanium.Android.ActionBar
icon : Stringwriteonly

Sets the application icon displayed in the "home" area of the action bar, specified as a local file path or URL.

Sets the application icon displayed in the "home" area of the action bar, specified as a local file path or URL.

Starting with Release 4.0, the action bar icon may not display. Google is discouraging the use of icons in toolbars.

Prior to Release 3.3.0, this method only works on devices with Android 4.0 (API 14) and above. See also: setIcon in the Android Developer Reference.

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.

  • 3.6.0
Titanium.Android.ActionBar
navigationMode : Number

Controls the navigation mode.

Controls the navigation mode.

The navigation mode can be NAVIGATION_MODE_STANDARD, or NAVIGATION_MODE_TABS. A TabGroup is initialized by Titanium Mobile with NAVIGATION_MODE_TABS, and can be hidden by setting to NAVIGATION_MODE_STANDARD. NAVIGATION_MODE_LIST is not yet supported. See also: setNavigationMode in the Android Developer Reference.

Titanium.Android.ActionBar
onHomeIconItemSelected : Callbackwriteonly

Callback function called when the home icon is clicked.

Callback function called when the home icon is clicked.

Titanium.Android.ActionBar
subtitle : String

Sets the subtitle of the action bar.

Sets the subtitle of the action bar.

  • 3.2.3
Titanium.Android.ActionBar
title : String

Sets the title of the action bar.

Sets the title of the action bar.

Defined By

Methods

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

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

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

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.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

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

Returns

  • void
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Android.ActionBar
( ) : Titanium.UI.View
Gets the value of the customView property. ...

Gets the value of the customView property.

  • 7.1.0

Returns

Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Android.ActionBar
( ) : Number
Gets the value of the navigationMode property. ...

Gets the value of the navigationMode property.

Returns

  • Number
Titanium.Android.ActionBar
( ) : String
Gets the value of the subtitle property. ...

Gets the value of the subtitle property.

  • 3.2.3

Returns

  • String
Titanium.Android.ActionBar
( ) : String
Gets the value of the title property. ...

Gets the value of the title property.

Returns

  • String
Titanium.Android.ActionBar
( )
Hides the action bar if it is currently showing. ...

Hides the action bar if it is currently showing.

See also: hide in the Android API Reference.

Returns

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

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

  • name : String

    Name of the event.

  • callback : Callback<Object>

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

Returns

  • void
Titanium.Android.ActionBar
( backgroundImage )
Sets the value of the backgroundImage property. ...

Sets the value of the backgroundImage property.

Parameters

  • backgroundImage : String

    New value for the property.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Titanium.Android.ActionBar
( customView )
Sets the value of the customView property. ...

Sets the value of the customView property.

  • 7.1.0

Parameters

Returns

  • void
Titanium.Android.ActionBar
( displayHomeAsUp )
Sets the value of the displayHomeAsUp property. ...

Sets the value of the displayHomeAsUp property.

Parameters

  • displayHomeAsUp : Boolean

    New value for the property.

Returns

  • void
Titanium.Android.ActionBar
( show )
Shows or hides the action bar home icon ...

Shows or hides the action bar home icon

See also: setDisplayShowHomeEnabled in the Android API Reference.

  • 3.3.0

Parameters

  • show : Boolean

    Boolean to show or hide action bar home icon

Returns

  • void
Titanium.Android.ActionBar
( show )
Shows or hides the action bar title/subtitle ...

Shows or hides the action bar title/subtitle

See also: setDisplayShowTitleEnabled in the Android API Reference.

  • 3.3.0

Parameters

  • show : Boolean

    Boolean to show or hide action bar title/subtitle

Returns

  • void
Titanium.Android.ActionBar
( homeButtonEnabled )
Sets the value of the homeButtonEnabled property. ...

Sets the value of the homeButtonEnabled property.

  • 3.3.0

Parameters

  • homeButtonEnabled : Boolean

    New value for the property.

Returns

  • void
Titanium.Android.ActionBar
( icon )
Sets the value of the icon property. ...

Sets the value of the icon property.

Parameters

  • icon : String

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.Android.ActionBar
( navigationMode )
Sets the value of the navigationMode property. ...

Sets the value of the navigationMode property.

Parameters

  • navigationMode : Number

    New value for the property.

Returns

  • void
Titanium.Android.ActionBar
( onHomeIconItemSelected )
Sets the value of the onHomeIconItemSelected property. ...

Sets the value of the onHomeIconItemSelected property.

Parameters

  • onHomeIconItemSelected : Callback

    New value for the property.

Returns

  • void
Titanium.Android.ActionBar
( subtitle )
Sets the value of the subtitle property. ...

Sets the value of the subtitle property.

  • 3.2.3

Parameters

  • subtitle : String

    New value for the property.

Returns

  • void
Titanium.Android.ActionBar
( title )
Sets the value of the title property. ...

Sets the value of the title property.

Parameters

  • title : String

    New value for the property.

Returns

  • void
Titanium.Android.ActionBar
( )
Shows the action bar if it is currently hidden. ...

Shows the action bar if it is currently hidden.

See also: show in the Android API Reference.

Returns

  • void