I'd look for an up key event, rather than a down event, with onKeyUp
.
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// ........
return true;
}
return super.onKeyUp(keyCode, event);
}
We return true
because we're handling the event; return false
if you want the system to handle the event too.
You can do all of this in your Activity
instance too because Activity
is a known indirect subclass of KeyEvent
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…