Android中某个类继承Activity的子类TabActivity时,重载Activity中的public boolean onKeyDown(int keyCode, KeyEvent event)方法时,点击按键时并得不到响应,解决的方法是:
重载public boolean dispatchKeyEvent(KeyEvent event)方法,其示例代码如下:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
响应事件的具体代码
}
return true;
}
return super.dispatchKeyEvent(event);
}