문제

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