# Titanium.Android.MenuItem

> The Titanium binding of an Android menu item.

- Source: https://titaniumsdk.com/docs/sdk/12.6.0/Titanium.Android.MenuItem
- Titanium SDK version: 12.6.0
- Kind: proxy
- Platforms: Android
- Since: Titanium SDK 1.5
- Extends: Titanium.Proxy
- Inheritance: Titanium.Proxy

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()](https://titaniumsdk.com/docs/sdk/Titanium.Android.Menu.md#add) method to create
new action items.

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

``` xml
<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](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#showAsAction).

You can optionally customize the look of action items using the
[actionView](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#actionView) property.

See the [Titanium.Android.Menu](https://titaniumsdk.com/docs/sdk/Titanium.Android.Menu.md) reference page for additional code examples.

Further Reading:

  * [Android Developers: MenuItem](https://developer.android.com/reference/android/view/MenuItem.html)

## Properties

### accessibilityHint

- Type: String
- Platforms: Android
- Since: Titanium SDK 8.3.0
- Default: `null`

Briefly describes what performing an action (such as a click) on the view will do.

Value of this property is concatenated together with
[Titanium.Android.MenuItem.accessibilityLabel](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#accessibilityLabel) and [Titanium.Android.MenuItem.accessibilityValue](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#accessibilityValue) in the order: `accessibilityLabel`,
`accessibilityValue`, `accessibilityHint`. The concatenated value is then passed as the
argument to the native [MenuItemCompat.setContentDescription](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat#setContentDescription(android.view.MenuItem,%20java.lang.CharSequence)) method.

### accessibilityLabel

- Type: String
- Platforms: Android
- Since: Titanium SDK 8.3.0
- Default: `null`

A succint label identifying the view for the device's accessibility service.

Value of this property is concatenated together with
[Titanium.Android.MenuItem.accessibilityValue](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#accessibilityValue) and [Titanium.Android.MenuItem.accessibilityHint](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#accessibilityHint) in the order: `accessibilityLabel`,
`accessibilityValue`, `accessibilityHint`. The concatenated value is then passed as the
argument to the native [MenuItemCompat.setContentDescription](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat#setContentDescription(android.view.MenuItem,%20java.lang.CharSequence)) method.

### accessibilityValue

- Type: String
- Platforms: Android
- Since: Titanium SDK 8.3.0
- Default: `null`

A string describing the value (if any) of the view for the device's accessibility service.

Value of this property is concatenated together with
[Titanium.Android.MenuItem.accessibilityLabel](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#accessibilityLabel) and [Titanium.Android.MenuItem.accessibilityHint](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#accessibilityHint) in the order: `accessibilityLabel`,
`accessibilityValue`, `accessibilityHint`. The concatenated value is then passed as the
argument to the native [MenuItemCompat.setContentDescription](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat#setContentDescription(android.view.MenuItem,%20java.lang.CharSequence)) method.

### actionView

- Type: Titanium.UI.View
- Platforms: Android
- Since: Titanium SDK 3.0.0

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](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#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:

``` xml
<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>
```

### actionViewExpanded

- Type: Boolean
- Platforms: Android
- Since: Titanium SDK 3.0.0
- Permission: read-only

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.

### checkable

- Type: Boolean
- Platforms: Android
- Default: `false`

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).

### checked

- Type: Boolean
- Platforms: Android
- Default: `false`

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).

### enabled

- Type: Boolean
- Platforms: Android
- Default: `true`

Determines if the item is enabled.

### groupId

- Type: Number
- Platforms: Android
- Permission: read-only

Group ID for this item.

Items that share a group ID may be operated on as a group using
the menu's [setGroupEnabled](https://titaniumsdk.com/docs/sdk/Titanium.Android.Menu.md#setGroupEnabled) and
[setGroupVisible](https://titaniumsdk.com/docs/sdk/Titanium.Android.Menu.md#setGroupVisible) methods.

### icon

- Type: Number | String
- Platforms: Android
- Permission: write-only

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.

### itemId

- Type: Number
- Platforms: Android
- Permission: read-only

Item ID for this item.

### order

- Type: Number
- Platforms: Android
- Permission: read-only

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](https://developer.android.com/reference/android/view/MenuItem.html#getOrder())
    in the Android Developer Reference.

*   [Menu](https://developer.android.com/reference/android/view/Menu.html) in the
    Android Developer Reference for definitions of the `CATEGORY` values.

### showAsAction

- Type: Number
- Platforms: Android
- Since: Titanium SDK 3.0.0
- Permission: write-only

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](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#SHOW_AS_ACTION_ALWAYS),
  [Titanium.Android.SHOW_AS_ACTION_IF_ROOM](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#SHOW_AS_ACTION_IF_ROOM),
  or [Titanium.Android.SHOW_AS_ACTION_NEVER](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#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](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#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](https://titaniumsdk.com/docs/sdk/Titanium.Android.md#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.

Accepts: `Titanium.Android.SHOW_AS_ACTION_ALWAYS`, `Titanium.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW`, `Titanium.Android.SHOW_AS_ACTION_IF_ROOM`, `Titanium.Android.SHOW_AS_ACTION_NEVER`, `Titanium.Android.SHOW_AS_ACTION_WITH_TEXT`

### title

- Type: String
- Platforms: Android

Title of the item.

### titleCondensed

- Type: String
- Platforms: Android

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.

### visible

- Type: Boolean
- Platforms: Android
- Default: `true`

Determines whether the menu item is visible.

## Methods

### collapseActionView

- Platforms: Android
- Since: Titanium SDK 3.0.0

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.

### expandActionView

- Platforms: Android
- Since: Titanium SDK 3.0.0

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.

### isActionViewExpanded

- Platforms: Android
- DEPRECATED since 10.0.0. Use the <Titanium.Android.MenuItem.actionViewExpanded> property instead.

Returns the [actionViewExpanded](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#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

### isCheckable

- Platforms: Android
- DEPRECATED since 10.0.0. Use the <Titanium.Android.MenuItem.checkable> property instead.

Returns the [checkable](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#checkable) state of the menu item.

Returns: Boolean

### isChecked

- Platforms: Android
- DEPRECATED since 10.0.0. Use the <Titanium.Android.MenuItem.checked> property instead.

Returns the [checked](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#checked) state of the menu item.

Returns: Boolean

### isEnabled

- Platforms: Android
- DEPRECATED since 10.0.0. Use the <Titanium.Android.MenuItem.enabled> property instead.

Returns the [enabled](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#enabled) state of the menu item.

Returns: Boolean

### isVisible

- Platforms: Android
- DEPRECATED since 10.0.0. Use the <Titanium.Android.MenuItem.visible> property instead.

Returns the [visible](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#visible) state of the menu item.

Returns: Boolean

### setCheckable

- Platforms: Android
- DEPRECATED since 10.0.0, removed in 10.0.0. Use the <Titanium.Android.MenuItem.checkable> property instead.

Sets the [checkable](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#checkable) state of the menu item.

Parameters:

- `checkable` (Boolean): True enable checking and unchecking this item, false to disable it.

### setChecked

- Platforms: Android
- DEPRECATED since 10.0.0, removed in 10.0.0. Use the <Titanium.Android.MenuItem.checked> property instead.

Sets the [checked](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#checked) state of the menu item.

Parameters:

- `enabled` (Boolean): True to check the item, false to uncheck it.

### setEnabled

- Platforms: Android
- DEPRECATED since 10.0.0, removed in 10.0.0. Use the <Titanium.Android.MenuItem.enabled> property instead.

Sets the [enabled](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#enabled) state of the menu item.

Parameters:

- `enabled` (Boolean): True to enable item, false to disable it.

### setVisible

- Platforms: Android
- DEPRECATED since 10.0.0, removed in 10.0.0. Use the <Titanium.Android.MenuItem.visible> property instead.

Sets the [visible](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#visible) state of the menu item.

Parameters:

- `visible` (Boolean): True to show the item, false to hide it.

## Events

### click

- Platforms: Android

Fired when the user clicks the menu item.

### collapse

- Platforms: Android
- Since: Titanium SDK 3.0.0

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.

### expand

- Platforms: Android
- Since: Titanium SDK 3.0.0

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.

## Inherited members

7 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.6.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `lifecycleContainer`, `removeEventListener`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

