Titanium.Android.Menu

On Android devices prior to Android 3.0 (API level 11), the menu is always presented
as an options menu, which is displayed when the Menu button is pressed.

On Android 3.0 and later, menu items can be displayed as action items in the action
bar. To enable this, the application must be built with a theme that supports the
action bar, such as the Holo theme. (See
Android Themes in
the Titanium Guides for information on setting your application's theme.)

To determine how an action item is displayed, set
showAsAction and optionally
actionView when creating a menu item.

Creating Menu Items

To create menu items with JavaScript, assign a callback function to the activity's
onCreateOptionsMenu property.
The activity's menu object is passed in to the onCreateOptionsMenu function when the menu is created.

In Alloy you can use <Menu> and <MenuItem> elements to create an options menu.

You must call invalidateOptionsMenu from the open event listener of the window or tab group
where the menu is defined.

For menu items displayed in the menu, the onCreateOptionsMenu function is called
once, and the onPrepareOptionsMenu callback function is called each
time the menu is opened. The onPrepareOptionsMenu function can be used to switch menu items dynamically.

When the action bar is in use, the menu is considered to be always open and
prepareOptionsMenu is never called. To switch menu items dynamically, call
invalidateOptionsMenu. This causes
the createOptionsMenu to be called again.

Menus on Tab Groups

Prior to Titanium 3.0, menu items could be added to the individual windows of a tab
group.

Starting in Titanium 3.0, menus must be added to tab groups using the tab group's
activity. These changes were required to support the Android 3.0 action bar.

The TabGroup activity is available using TabGroup.getActivity.
However, unlike a window's activity it is not currently possible to set properties on
the tab group's activity before the tab group is opened. To add a menu to a tab group,
set the onCreateOptionsMenu property to the tab group's open event listener, and
then call invalidateOptionsMenu to force the changes to take effect.

Alloy XML Markup

Previous simple menu example as an Alloy view.

Due to the way menus are created in Alloy, menus created using Alloy markup are not
displayed until the options menu is invalidated. To force menus (or action items)
to be displayed, call invalidateOptionsMenu from the open event listener of the window or tab group
where the menu is defined.

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.

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.