如果想要实现按menu键后,和按返回键相同的效果关闭菜单menu。
可以使用Activity.java中的closeOptionsMenu()来实现
/**
* Progammatically closes the options menu. If the options menu is already
* closed, this method does nothing.
*/
public void closeOptionsMenu() {
if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) &&
(mActionBar == null || !mActionBar.closeOptionsMenu())) {
mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL);
}
}
此方法是以编程方式关闭选项菜单。 选项菜单已经关闭,这个方法什么也不做。
但是只能关闭第一层menu,无法关闭两层以上的子菜单submenu。