Sahar Zehavi
Sahar Zehavi

Reputation: 590

How to make a button in android to pops up a menu?

I want a menu (the one that is triggered by the Menu button on the device) to work from a click on a normal button (an on screen one, of course).. in a way to "replace" the Menu button on the device on one that is on screen.

Any ideas?

Upvotes: 0

Views: 284

Answers (2)

Todd Sjolander
Todd Sjolander

Reputation: 1567

Here's one way. I use this in my code, and it works really great.

Edit: I think I misunderstood your intention. If you want to programmatically launch the standard menu (as if the menu button was pressed) at some other time, call openOptionsMenu();.

Upvotes: 0

Jameo
Jameo

Reputation: 4617

Easily

public void onClick(View v){
    openOptionsMenu(); 
}

Then to override the menu buttons behavior (this is not really reccomended) you can do something like this

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ( keyCode == KeyEvent.KEYCODE_MENU ) {
        Log.d(TAG, "MENU pressed");
        return false;
    }
    return super.onKeyDown(keyCode, event);
}

Upvotes: 1

Related Questions