Search code examples
androidandroid-actionbaroverflow-menu

Detect click on Actionbar's Overflow menu button


Can I detect click/tap on the menu button of action bar, i.e. used to show overflow menu items?

By default it opens up the list with one item "Settings". Here is the screenshot:

Until now it is detecting click on "2" but I want to detect click on "1".


Solution

  • Finally i found the solution. Override FragmentActivity.onKeyDown

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        switch (keyCode) {
    
        case KeyEvent.KEYCODE_MENU:
            // Do Sometihng
            break;
    
        default:
            break;
        }
        return super.onKeyDown(keyCode, event);
    }