summaryrefslogtreecommitdiff
path: root/core/java/android/view/MenuInflater.java
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2010-06-10 18:58:59 -0700
committerAdam Powell <adamp@google.com>2010-06-17 11:35:43 -0700
commit96675b1df3969f2d313b68f60ed9fa36805db8ce (patch)
tree0bf8088a354d1e4f392a6adccda1911c0a0d890e /core/java/android/view/MenuInflater.java
parente6ac8b9aade9443ab8456c8f7a47cdfba3b70266 (diff)
Merging ActionBar menu with options menu.
Options menu items may now specify if they would like to appear in the action bar. Menu items defined in xml may set the showAsAction attribute to one of "never"(default), "ifRoom", or "always". Action buttons are populated as follows: * All showAsAction="always" items become action buttons, even if it would crowd the navigation area of the action bar. * If there is space remaining, showAsAction="ifRoom" items are added until no more will fit comfortably. Action button click events are now handled by the onOptionsItemSelected method used by the standard options menu. The construction of options menus now happens earlier in order to provide data to the action bar. Activities with an action bar can now expect to have onCreateOptionsMenu called when activity start-up is complete. Activity#invalidateOptionsMenu can be used to force a refresh of menu items where the previous API would use ActionBar#updateActionMenu. Change-Id: If52ddf1cf9f6926206bcdeadf42072ea2c24fab9
Diffstat (limited to 'core/java/android/view/MenuInflater.java')
-rw-r--r--core/java/android/view/MenuInflater.java17
1 files changed, 15 insertions, 2 deletions
diff --git a/core/java/android/view/MenuInflater.java b/core/java/android/view/MenuInflater.java
index a37d83dd36db..3335e85436c8 100644
--- a/core/java/android/view/MenuInflater.java
+++ b/core/java/android/view/MenuInflater.java
@@ -241,6 +241,14 @@ public class MenuInflater {
private boolean itemVisible;
private boolean itemEnabled;
+ /**
+ * Sync to attrs.xml enum:
+ * - 0: never
+ * - 1: ifRoom
+ * - 2: always
+ */
+ private int itemShowAsAction;
+
private String itemListenerMethodName;
private static final int defaultGroupId = NO_ID;
@@ -314,6 +322,7 @@ public class MenuInflater {
itemChecked = a.getBoolean(com.android.internal.R.styleable.MenuItem_checked, defaultItemChecked);
itemVisible = a.getBoolean(com.android.internal.R.styleable.MenuItem_visible, groupVisible);
itemEnabled = a.getBoolean(com.android.internal.R.styleable.MenuItem_enabled, groupEnabled);
+ itemShowAsAction = a.getInt(com.android.internal.R.styleable.MenuItem_showAsAction, 0);
itemListenerMethodName = a.getString(com.android.internal.R.styleable.MenuItem_onClick);
a.recycle();
@@ -344,8 +353,12 @@ public class MenuInflater {
new InflatedOnMenuItemClickListener(mContext, itemListenerMethodName));
}
- if (itemCheckable >= 2 && item instanceof MenuItemImpl) {
- ((MenuItemImpl) item).setExclusiveCheckable(true);
+ if (item instanceof MenuItemImpl) {
+ MenuItemImpl impl = (MenuItemImpl) item;
+ if (itemCheckable >= 2) {
+ impl.setExclusiveCheckable(true);
+ }
+ impl.setShowAsAction(itemShowAsAction);
}
}