Catch a click on a menu

how can I intercept a click on a device’s menu button (for example, a phone). I need something like OnMenuClick() .

+4
source share
4 answers

I decide it myself, like this

 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_MENU||keyCode == KeyEvent.KEYCODE_BACK) && event.getRepeatCount() == 0) { // my code here... } } 
+3
source

You need to implement 2 things.

  • onCreateOptionsMenu ()
  • onOptionMenuItemClick ().

All click events will appear before 2.

An example is here .

0
source

You can access it when the menu opens using onMenuOpened ()

0
source

implementation of

onPrepareOptionsMenu (menu menu)

it is called every time the menu button is pressed

0
source

All Articles