Skip to content Skip to sidebar Skip to footer

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.

Solution 1:

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

There is a KEYCODE_MENU you can catch.

Solution 2:

in your Activity:

@OverridepublicbooleandispatchKeyEvent(KeyEvent event) {
   finalintkeycode= event.getKeyCode();
   finalintaction= event.getAction();
    if (keycode == KeyEvent.KEYCODE_MENU && action == KeyEvent.ACTION_UP) {
        returntrue; // consume the key press
    }
    returnsuper.dispatchKeyEvent(event);
}

Credits to original answer

Solution 3:

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.

Solution 4:

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

Post a Comment for "How Can I Disable The Hardware Menu Button In My App?"