Titanium.Android.MenuItem
> Titanium.Android.MenuItem

The Titanium binding of an Android menu item.

As of Release 3.3.0, the Menu and MenuItem APIs are used to create action items for the action bar. Prior to Release 3.3.0, the APIs could also be used to customize the Options Menu.

In JavaScript, use the Menu's add() method to create new action items.

In Alloy you can define <MenuItem> elements inside a <Menu> element.

<Menu id="menu" platform="android">
    <MenuItem id="saveitem" title="Save" icon="item1.png" onClick="doSave" />
    <MenuItem id="closeitem" title="Close" icon="item1.png" onClick="doClose" />
</Menu>

Action items can appear in either the action bar or the action bar's overflow menu. To determine how an action item is displayed, set showAsAction.

You can optionally customize the look of action items using the actionView property.

See the Titanium.Android.Menu reference page for additional code examples.

Further Reading:

  • 1.5
Defined By

Properties

Titanium.Android.MenuItem
actionView : Titanium.UI.View

Custom view that replaces the default menu item button.

Custom view that replaces the default menu item button.

This is an action-bar specific API. Prior to Release 3.3.0, this API only works on devices running Android 3.0 (API level 11) and greater.

In order to display the custom view, set the item's showAsAction property to either Titanium.Android.SHOW_AS_ACTION_ALWAYS or Titanium.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.

Since Alloy 1.6.0, you can specify this property using the <ActionView> element as a child of the <MenuItem> element, for example:

<Alloy>
    <Window>
        <Menu>
            <MenuItem showAsAction="Ti.Android.SHOW_AS_ACTION_ALWAYS" title="Search">
                <ActionView>
                    <SearchView ns="Ti.UI.Android" hintText="Type Something"/>
                </ActionView>
            </MenuItem>
        </Menu>
    </Window>
</Alloy>
  • 3.0.0
Titanium.Android.MenuItem
actionViewExpanded : Booleanreadonly

True if this menu item's action view has been expanded.

True if this menu item's action view has been expanded.

This is an action-bar specific API. Prior to Release 3.3.0, this API only works on devices running Android 4.0 (API level 14) and greater.

  • 3.0.0
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
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.MenuItem
: Boolean
Determines if the item can be checked. ...

Determines if the item can be checked.

Note that check marks are not supported in the icon menus (main options menu shown when fewer than six options are included). Check marks are discouraged in expanded menus (available when six or more options menu items are defined).

Default: false

Titanium.Android.MenuItem
: Boolean
Determines if the item is checked. ...

Determines if the item is checked.

Note that check marks are not supported in the icon menus (main options menu shown when fewer than six options are included). Check marks are discouraged in expanded menus (available when six or more options menu items are defined).

Default: false

Titanium.Android.MenuItem
: Boolean
Determines if the item is enabled. ...

Determines if the item is enabled.

Default: true

Titanium.Android.MenuItem
groupId : NumberreadonlyCreation-Only

Group ID for this item.

Group ID for this item.

Items that share a group ID may be operated on as a group using the menu's setGroupEnabled and setGroupVisible methods.

Titanium.Android.MenuItem
icon : Number/Stringwriteonly

Icon to display for the this menu item.

Icon to display for the this menu item.

Icons are not displayed in expanded menus.

Icons can be specified as a local image URI or an Android resource ID.

Titanium.Android.MenuItem
itemId : NumberreadonlyCreation-Only

Item ID for this item.

Item ID for this item.

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.MenuItem
order : NumberreadonlyCreation-Only

Integer used for controlling the category and sort order for menu items.

Integer used for controlling the category and sort order for menu items.

The lower bits of this value control the order of the menu item related to other menu items within its category. A menu item with a given value will be displayed before any items with higher values.

The upper bits of the value control the category. These can be set to the values defined by the CATEGORY constants in the Android Menu class, These values are not exposed as constants in Titanium.

See also:

  • getOrder in the Android Developer Reference.

  • Menu in the Android Developer Reference for definitions of the CATEGORY values.

Titanium.Android.MenuItem
showAsAction : Numberwriteonly

A set of flags that controls how this item appears in the action bar.

A set of flags that controls how this item appears in the action bar.

This is an action-bar specific API. Prior to Release 3.3.0, this property only works on devices running Android 3.0 (API level 11) and greater.

You may set one or more flags (by OR'ing them together) to control how this menu item should be placed inside the action bar.

To control if your item should be displayed as an action button or placed in the overflow menu set one of these flags: Titanium.Android.SHOW_AS_ACTION_ALWAYS, Titanium.Android.SHOW_AS_ACTION_IF_ROOM, or Titanium.Android.SHOW_AS_ACTION_NEVER.

If you only wish to display the text label even if the item has an icon set the Titanium.Android.SHOW_AS_ACTION_WITH_TEXT flag. Note that the SHOW_AS_ACTION_WITH_TEXT setting is only a hint to the system -- the text may or may not be shown depending on the width of the screen. For example, text may not be shown on phones in portrait mode. In addition if the application can be displayed in both portrait and landscape mode, whether or not the text is displayed depends on the device's orientation when the application launches. (This is true of both Titanium applications and native Android applications.) For this reason, using SHOW_AS_ACTION_WITH_TEXT is not recommended for applications that support both orientions.

If you want to guarantee that text and icon are always visible, you can create a button with the text and image, and specify it as the item's actionView.

You may specify if your action view is collapsible by setting this property to Titanium.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.

For a collapsible item, the item button (icon and/or text) is displayed when the item is collapsed, and the action view is displayed when the item is expanded.

If SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW is not specified, any actionView specified is displayed instead of the item's icon and/or text.

This API can be assigned the following constants:

  • 3.0.0
Titanium.Android.MenuItem
title : String

Title of the item.

Title of the item.

Titanium.Android.MenuItem
titleCondensed : String

Shortened version of the item's title.

Shortened version of the item's title.

If both title and titleCondensed are specified, titleCondensed is used in the icon menus, and the title is used in the extended menus.

Titanium.Android.MenuItem
: Boolean
Determines whether the menu item is visible. ...

Determines whether the menu item is visible.

Default: true

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
Titanium.Android.MenuItem
( )
Collapse the action view associated with this menu item. ...

Collapse the action view associated with this menu item.

This is an action-bar specific API. Prior to Release 3.3.0, this API only works on devices running Android 4.0 (API level 14) and greater.

  • 3.0.0

Returns

  • void
Titanium.Android.MenuItem
( )
Expand the action view associated with this menu item. ...

Expand the action view associated with this menu item.

This is an action-bar specific API. Prior to Release 3.3.0, this API only works on devices running Android 3.0 (API level 11) and greater.

  • 3.0.0

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
Titanium.Android.MenuItem
( ) : Titanium.UI.View
Gets the value of the actionView property. ...

Gets the value of the actionView property.

  • 3.0.0

Returns

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.MenuItem
( ) : Number
Gets the value of the groupId property. ...

Gets the value of the groupId property.

Returns

  • Number
Titanium.Android.MenuItem
( ) : Number
Gets the value of the itemId property. ...

Gets the value of the itemId property.

Returns

  • Number
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Android.MenuItem
( ) : Number
Gets the value of the order property. ...

Gets the value of the order property.

Returns

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

Gets the value of the title property.

Returns

  • String
Titanium.Android.MenuItem
( ) : String
Gets the value of the titleCondensed property. ...

Gets the value of the titleCondensed property.

Returns

  • String
Titanium.Android.MenuItem
( ) : Boolean
Returns the actionViewExpanded state of the menu item. ...

Returns the actionViewExpanded state of the menu item.

This is an action-bar specific API. Prior to Release 3.3.0, this API only works on devices running Android 4.0 (API level 14) and greater.

Returns

  • Boolean
Titanium.Android.MenuItem
( ) : Boolean
Returns the checkable state of the menu item. ...

Returns the checkable state of the menu item.

Returns

  • Boolean
Titanium.Android.MenuItem
( ) : Boolean
Returns the checked state of the menu item. ...

Returns the checked state of the menu item.

Returns

  • Boolean
Titanium.Android.MenuItem
( ) : Boolean
Returns the enabled state of the menu item. ...

Returns the enabled state of the menu item.

Returns

  • Boolean
Titanium.Android.MenuItem
( ) : Boolean
Returns the visible state of the menu item. ...

Returns the visible state of the menu item.

Returns

  • Boolean
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.MenuItem
( actionView )
Sets the value of the actionView property. ...

Sets the value of the actionView property.

  • 3.0.0

Parameters

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.MenuItem
( checkable )
Sets the checkable state of the menu item. ...

Sets the checkable state of the menu item.

Parameters

  • checkable : Boolean

    True enable checking and unchecking this item, false to disable it.

Returns

  • void
Titanium.Android.MenuItem
( enabled )
Sets the checked state of the menu item. ...

Sets the checked state of the menu item.

Parameters

  • enabled : Boolean

    True to check the item, false to uncheck it.

Returns

  • void
Titanium.Android.MenuItem
( enabled )
Sets the enabled state of the menu item. ...

Sets the enabled state of the menu item.

Parameters

  • enabled : Boolean

    True to enable item, false to disable it.

Returns

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

Sets the value of the icon property.

Parameters

  • icon : Number/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.MenuItem
( showAsAction )
Sets the value of the showAsAction property. ...

Sets the value of the showAsAction property.

  • 3.0.0

Parameters

  • showAsAction : Number

    New value for the property.

Returns

  • void
Titanium.Android.MenuItem
( 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.MenuItem
( titleCondensed )
Sets the value of the titleCondensed property. ...

Sets the value of the titleCondensed property.

Parameters

  • titleCondensed : String

    New value for the property.

Returns

  • void
Titanium.Android.MenuItem
( visible )
Sets the visible state of the menu item. ...

Sets the visible state of the menu item.

Parameters

  • visible : Boolean

    True to show the item, false to hide it.

Returns

  • void
Defined By

Events

Titanium.Android.MenuItem
Fired when the user clicks the menu item. ...

Fired when the user clicks the menu item.

Properties

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

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

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Titanium.Android.MenuItem
Fired when the action view has been collapsed. ...

Fired when the action view has been collapsed.

This is an action-bar specific API. Prior to Release 3.3.0, this API only works on devices running Android 4.0 (API level 14) and greater.

  • 3.0.0

Properties

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

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

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Titanium.Android.MenuItem
Fired when the action view has been expanded. ...

Fired when the action view has been expanded.

This is an action-bar specific API. Prior to Release 3.3.0, this API only works on devices running Android 4.0 (API level 14) and greater.

  • 3.0.0

Properties

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

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

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •