How to open the options menu programmatically? How to open the options menu programmatically? android android

How to open the options menu programmatically?


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

@Overridepublic 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();