Search code examples
javaandroideclipsemenuhardware-interface

Using the Hardware Button "Menu" from Android with Java


I am just about to learn myself how to create an android app. Right now I am looking for a way to use the menu hardware button. I read that I have to create a xml file, but i don't understand where I have to save that to? And what is the code for grab the menu button? Can anyone show me a simple example?


Solution

  • There are lots of examples on this website, you can create a function on your activity to catch the event:

    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            if (event.getAction() == KeyEvent.ACTION_UP)
            {
                //your code
                return true;
            }
        }
        return super.onKeyUp(keyCode, event);
    }