My app has an Activity that needs 'back' and 'menu' hardware buttons disabled. I disabled the 'back' one with onBackPressed
but I have no idea how to disable the menu button.
Asked
Active
Viewed 2,170 times
0

Jimmy A. León
- 541
- 3
- 6
- 22
-
Override the Menu Key like this: http://stackoverflow.com/questions/19202165/overriding-the-physical-menu-button-on-android – Mariano Zorrilla Sep 03 '15 at 19:44
-
1Be careful, this can totally break the user experience. – Egor Sep 03 '15 at 19:45
-
It didn't work for me. – Jimmy A. León Sep 03 '15 at 21:01
4 Answers
1
You should try the key event onKeyDown(). That worked for me.
There is a KEYCODE_MENU you can catch.

Cacho Santa
- 6,846
- 6
- 41
- 73
0
in your Activity
:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
final int keycode = event.getKeyCode();
final int action = event.getAction();
if (keycode == KeyEvent.KEYCODE_MENU && action == KeyEvent.ACTION_UP) {
return true; // consume the key press
}
return super.dispatchKeyEvent(event);
}
Credits to original answer

Community
- 1
- 1

Ivan Bartsov
- 19,664
- 7
- 61
- 59
0
Update your Gradle files for the app, so you have a current compileSdkVersion,buildToolsVersion, minSdkVersion and targetSdkVersion. Then update your Gradle files for the project so you have the current classpath for Gradle, for instance 'com.android.tools.build:gradle:1.5.0'. This solved the problem for me. I tried the solutions suggested above, but they did not work.

Eyvind Almqvist
- 150
- 11
0
I have fix this question in my activity through override onKeyUp(if keyCode is KeyEvent.Menu return true)

ErLiang
- 1
- 1