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
  • 501
  • 2
  • 6
  • 21

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,668
  • 5
  • 37
  • 70
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
  • 17,904
  • 6
  • 57
  • 58
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