From 14711b2b420e034cf1050d3cb887e4735792e080 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Mon, 29 Nov 2010 16:45:49 -0800 Subject: [PATCH] docs: updates to menu resource doc for new attributes Change-Id: I6dd0553da6153839b54e4429db5e87d071e91e49 --- .../guide/topics/resources/menu-resource.jd | 63 ++++++++++++++++--- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/docs/html/guide/topics/resources/menu-resource.jd b/docs/html/guide/topics/resources/menu-resource.jd index 7bcd78a5196d6..33c782b1c0530 100644 --- a/docs/html/guide/topics/resources/menu-resource.jd +++ b/docs/html/guide/topics/resources/menu-resource.jd @@ -39,7 +39,10 @@ In XML: @[package:]menu.filename android:title="string" android:titleCondensed="string" android:icon="@[package:]drawable/drawable_resource_name" + android:onClick="method name" android:showAsAction=["ifRoom" | "never" | "withText" | "always"] + android:actionLayout="@[package:]layout/layout_resource_name" + android:actionViewClass="class name" android:alphabeticShortcut="string" android:numericShortcut="string" android:checkable=["true" | "false"] @@ -74,8 +77,8 @@ In XML: @[package:]menu.filename

attributes:

xmlns:android
-
String. Required. Defines the XML namespace, which must be - "http://schemas.android.com/apk/res/android". +
XML namespace. Required. Defines the XML namespace, which +must be "http://schemas.android.com/apk/res/android".
@@ -89,13 +92,26 @@ In XML: @[package:]menu.filename "@+id/name". The plus symbol indicates that this should be created as a new ID.
android:title
-
String. The menu title.
+
String resource. The menu title as a string resource or raw string.
android:titleCondensed
-
String. A condensed title, for situations in which the normal title is -too long.
+
String resource. A condensed title as a string resource or a raw string. This +title is used for situations in which the normal title is too long.
+
android:icon
Drawable resource. An image to be used as the menu item icon.
+
android:onClick
+
Method name. The method to call when this menu item is clicked. The +method must be declared in the activity as public and accept a {@link android.view.MenuItem} as its +only parameter, which indicates the item clicked. This method takes precedence over the standard +callback to {@link android.app.Activity#onOptionsItemSelected onOptionsItemSelected()}. See the +example at the bottom. +

Warning: If you obfuscate your code using ProGuard (or a similar tool), +be sure to exclude the method you specify in this attribute from renaming, because it can break the +functionality.

+

Introduced in API Level HONEYCOMB.

+
android:showAsAction
Keyword. When and how this item should appear as an action item in the Action Bar. A menu item can appear as an action item only when the activity includes an {@link @@ -118,6 +134,24 @@ more information.

Introduced in API Level HONEYCOMB.

+
android:actionViewLayout
+
Layout resource. A layout to use as the action view. +

See Using the Action Bar for +more information.

+

Introduced in API Level HONEYCOMB.

+ +
android:actionViewClassName
+
Class name. A fully-qualified class name for the {@link android.view.View} +to use as the action view. +

See Using the Action Bar for +more information.

+

Warning: If you obfuscate your code using ProGuard (or a similar tool), +be sure to exclude the class you specify in this attribute from renaming, because it can break the +functionality.

+

Introduced in API Level HONEYCOMB.

+ +
android:alphabeticShortcut
Char. A character for the alphabetic shortcut key.
android:numericShortcut
@@ -208,9 +242,11 @@ on the data that is currently displayed. android:showAsAction="ifRoom|withText"/> <group android:id="@+id/group"> <item android:id="@+id/group_item1" + android:onClick="onGroupItemClick" android:title="@string/group_item1" android:icon="@drawable/group_item1_icon" /> <item android:id="@+id/group_item2" + android:onClick="onGroupItemClick" android:title="G@string/group_item2" android:icon="@drawable/group_item2_icon" /> </group> @@ -224,13 +260,20 @@ on the data that is currently displayed. </item> </menu> -

This application code will inflate the menu from the {@link -android.app.Activity#onCreateOptionsMenu(Menu)} callback:

+

The following application code inflates the menu from the {@link +android.app.Activity#onCreateOptionsMenu(Menu)} callback and also declares the on-click +callback for two of the items:

 public boolean onCreateOptionsMenu(Menu menu) {
-  MenuInflater inflater = getMenuInflater();
-  inflater.inflate(R.menu.example_menu, menu);
-  return true;
+    MenuInflater inflater = getMenuInflater();
+    inflater.inflate(R.menu.example_menu, menu);
+    return true;
+}
+
+public void onGroupItemClick(MenuItem item) {
+    // One of the group items (using the onClick attribute) was clicked
+    // The item parameter passed here indicates which item it is
+    // All other menu item clicks are handled by {@link android.app.Activity#onOptionsItemSelected onOptionsItemSelected()}
 }
 

Note: The {@code android:showAsAction} attribute is