@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.d("gxqtest", "enter onCreateOptionsMenu");
menu.add("hi I am menu one");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
Log.d("gxqtest", "enter onPrepareOptionsMenu");
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
Log.d("gxqtest", "enter onMenuOpened");
return super.onMenuOpened(featureId, menu);
}
@Override
public void onOptionsMenuClosed(Menu menu) {
Log.d("gxqtest", "enter onOptionsMenuClosed");
super.onOptionsMenuClosed(menu);
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/**
* Initialize the contents of the Activity's standard options menu. You
* should place your menu items in to <var>menu</var>.
*
* <p>This is only called once, the first time the options menu is
* displayed. To update the menu every time it is displayed, see
* {@link #onPrepareOptionsMenu}.
*
* <p>The default implementation populates the menu with standard system
* menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that
* they will be correctly ordered with application-defined menu items.
* Deriving classes should always call through to the base implementation.
*
* <p>You can safely hold on to <var>menu</var> (and any items created
* from it), making modifications to it as desired, until the next
* time onCreateOptionsMenu() is called.
*
* <p>When you add items to the menu, you can implement the Activity's
* {@link #onOptionsItemSelected} method to handle them there.
*
* @param menu The options menu in which you place your items.
*
* @return You must return true for the menu to be displayed;
* if you return false it will not be shown.
*
* @see #onPrepareOptionsMenu
* @see #onOptionsItemSelected
*/
public boolean onCreateOptionsMenu(Menu menu) {
if (mParent != null) {
return mParent.onCreateOptionsMenu(menu);
}
return true;
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/**
* Prepare the Screen's standard options menu to be displayed. This is
* called right before the menu is shown, every time it is shown. You can
* use this method to efficiently enable/disable items or otherwise
* dynamically modify the contents.
*
* <p>The default implementation updates the system menu items based on the
* activity's state. Deriving classes should always call through to the
* base class implementation.
*
* @param menu The options menu as last shown or first initialized by
* onCreateOptionsMenu().
*
* @return You must return true for the menu to be displayed;
* if you return false it will not be shown.
*
* @see #onCreateOptionsMenu
*/
public boolean onPrepareOptionsMenu(Menu menu) {
if (mParent != null) {
return mParent.onPrepareOptionsMenu(menu);
}
return true;
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/**
* {@inheritDoc}
*
* @return The default implementation returns true.
*/
public boolean onMenuOpened(int featureId, Menu menu) {
if (featureId == Window.FEATURE_ACTION_BAR) {
initActionBar();
if (mActionBar != null) {
mActionBar.dispatchMenuVisibilityChanged(true);
} else {
Log.e(TAG, "Tried to open action bar menu with no action bar");
}
}
return true;
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
关于popupwindow替代传统menu的问题,
1.popupwindow弹出后,按menu key消失
要解决这个问题很简单,就是给PopupWindow的子View设置下面的代码:
可解决这个问题。
可参考 http://blog.csdn.net/admin_/article/details/7278402