Reputation: 590
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
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
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