// 构建一个menubuilder对象 public MenuBuilder(Context context) { mContext = context; mResources = context.getResources(); mItems = new ArrayList<MenuItemImpl>(); mVisibleItems = new ArrayList<MenuItemImpl>(); mIsVisibleItemsStale = true; mActionItems = new ArrayList<MenuItemImpl>(); mNonActionItems = new ArrayList<MenuItemImpl>(); mIsActionItemsStale = true; setShortcutsVisibleInner(true); }
/** * * Sets whether the shortcuts should be visible on menus. Devices without hardware key input * will never make shortcuts visible even if this method is passed 'true'. * * @param shortcutsVisible Whether shortcuts should be visible (if true and a menu item does not * have a shortcut defined, that item will still NOT show a shortcut) */ public void setShortcutsVisible(boolean shortcutsVisible) { if (mShortcutsVisible == shortcutsVisible) return; setShortcutsVisibleInner(shortcutsVisible); onItemsChanged(false); }