Michael A
Michael A

Reputation: 5840

Open Menu from a button click

I have this code for showing a Menu:

public boolean onCreateOptionsMenu(Menu menu) {
    this.menu = menu;
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.Email_settings:
 //    startActivity(new Intent(this, About.class));
    return true;
    case R.id.Help_settings:
//     startActivity(new Intent(this, Help.class));
    return true;
    default:
    return super.onOptionsItemSelected(item);
    }
}

The code works fine when pressing the device options button.

How can i open the menu on a button click from inside my screen and not the device options button?

Upvotes: 0

Views: 332

Answers (2)

Sam
Sam

Reputation: 1662

Use Activity.openOptionsMenu() method.

Docs reference

Be sure to use this method only after options menu is instanciated(onCreateOptionsMenu was already executed)

Upvotes: 1

vipul mittal
vipul mittal

Reputation: 17401

call

openOptionsMenu();

on Click event

Upvotes: 1

Related Questions