Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the options menu programmatically?

Or just call Activity.openOptionsMenu()?


Apparently, doing it in onCreate breaks app, since Activity's not yet attached to a window. If you do it like so:

@Override
public void onAttachedToWindow() {
    openOptionsMenu(); 
};

...it works.


For developers using the new Toolbar class of the Support Library, this is how it's done:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.showOverflowMenu();

Put this line of code in your onResume(), this should help!

new Handler().postDelayed(new Runnable() { 
   public void run() { 
     openOptionsMenu(); 
   } 
}, 1000);