Skip to content Skip to sidebar Skip to footer

Openoptionsmenu Not Working With Actionbarsherlock Custom Submenu

In my application, I am using ActionBarSherlock 4.4. Since ForcedOverflow has been removed from the latest version, I used the following XML code to replicate the OverflowMenu. <

Solution 1:

I was having the same issue as you today. I think this is because ActionBarSherlock has its own implementation of the options menu which overrides Android's one, disabling the openOptionsMenu() method in the process. Maybe it's a bug in the library?

Anyway, I solved this by overriding onKeyUp in the activity containing the menu as follows:

@OverridepublicbooleanonKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        Viewv= findViewById(R.id.YOUR_MENU_VIEW_HERE);
        v.performClick();
        returntrue;
    }
    returnsuper.onKeyUp(keyCode, event);
}

Hope it helps.

Solution 2:

This is how I solved the issue but Ricardo's answer works as well.

privateMenu optionsMenu;
    @OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.getSupportMenuInflater().inflate(R.menu.display_all, menu);
        optionsMenu = menu;
        returntrue;
    }

    @OverridepublicbooleanonKeyUp(int keyCode, KeyEvent event) { 
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            if (event.getAction() == KeyEvent.ACTION_UP &&
                    keyCode == KeyEvent.KEYCODE_MENU) {
                //openOptionsMenu();
                optionsMenu.performIdentifierAction(R.id.menu_overflow, 0);
                returntrue;
            }
        }
        returnsuper.onKeyUp(keyCode, event);
    }

Post a Comment for "Openoptionsmenu Not Working With Actionbarsherlock Custom Submenu"