Android --- Close menu menu

If you want to achieve the same effect of pressing the menu key as pressing the return key to close the menu.
This can be achieved using closeOptionsMenu() in Activity.java

    /**
     * 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);
        }
    }

This method is to programmatically close the options menu. The options menu is closed and this method does nothing.

However, only the first level menu can be closed, and submenus with more than two levels cannot be closed.

Guess you like

Origin blog.csdn.net/m0_50408097/article/details/125502447