Override Button Action

Nexus displays the screen as follows: (Here I click on 3 dots in the upper right corner to release the menu)

enter image description here

I have a menu in the upper right corner of the screen. The phone displays the menu as follows (This only happens when you press the menu button on the phone):

enter image description here

I would like to have the same behavior on the phone as on the tablet, where I can show the menu in the upper right corner of the screen. My question here is whether there is a way to override the bloat menu behavior, somewhere in the menu should be displayed in the upper right corner of the screen even on the phone.

+4
source share
1 answer

This is a bit complicated, but here is a general idea:

public void showPopup(View v) { PopupMenu popup = new PopupMenu(this, v); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.layout.menu, popup.getMenu()); popup.show(); 

}

In this method, v displays the view that you want your menu to display.

You will need the Override menu button so that when the user clicks, your menu appears. Do the following

 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ( keyCode == KeyEvent.KEYCODE_MENU ) { //Put the code for an action menu from the top here return true; } return super.onKeyDown(keyCode, event); } 

And then everything else will be the same as for your regular menu (I think)

+5
source

All Articles