I would like to open the optionsMenu programmatically without a click on the menu key from the user. How would I do that?
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(0xFFFFFFFF);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
toolbar.showOverflowMenu();
}
}, 100);
Put this line of code in your onResume(), this should help!
new Handler().postDelayed(new Runnable() {
public void run() {
openOptionsMenu();
}
}, 1000);
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();
if using AppCompatActivity
getSupportActionBar().openOptionsMenu();
Or just call Activity.openOptionsMenu()?