0

I'm making a game with OpenGL Es 1.1 and i want to implement back button or menu button functionality to my game.(I mean hardware buttons).I have some subClasses so what i have to do when i want to handle hardware button press from subClasses?

4

1 回答 1

2

You need to implement an onKeyDown listener and check to see what key is pressed.

Sample:

@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
     switch(keycode) {
         case KeyEvent.KEYCODE_MENU:
             handleMenuButton();
             return true;
         case KeyEvent.KEYCODE_BACK:
             handleBackButton();
             return true;
     }
     return super.onKeyDown(keycode, e);
} 

Also note that for the back and menu buttons to fire reliably, you need to set setFocusableInTouchMode to true. See the devguide here (scroll down to "Touch Mode").

于 2012-05-26T16:51:15.950 回答