Question

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?

Was it helpful?

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top