0

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.

Jimmy A. León
  • 541
  • 3
  • 6
  • 22

4 Answers4

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.

0

I have fix this question in my activity through override onKeyUp(if keyCode is KeyEvent.Menu return true)

ErLiang
  • 1
  • 1