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?

有帮助吗?

解决方案

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top