Jimmy A. León
Jimmy A. León

Reputation: 561

How can I disable the hardware menu button in my app?

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.

Upvotes: 0

Views: 2220

Answers (4)

ErLiang
ErLiang

Reputation: 1

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

Upvotes: 0

Eyvind Almqvist
Eyvind Almqvist

Reputation: 332

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.

Upvotes: 0

Ivan Bartsov
Ivan Bartsov

Reputation: 21086

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

Upvotes: 0

Cacho Santa
Cacho Santa

Reputation: 6914

You should try the key event onKeyDown(). That worked for me.

There is a KEYCODE_MENU you can catch.

Upvotes: 1

Related Questions