我得到
D/InputEventConsistencyVerifier( 2144): KeyEvent: ACTION_UP but key was not down.`
D/InputEventConsistencyVerifier( 2144): in com.android.internal.policy.impl.PhoneWindow$DecorView@41689658
当我在活动中尝试执行此操作时,到处都是警告:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if ((/*some boolean checks*/) && (event.getAction() == KeyEvent.ACTION_DOWN)) {
/*some custom functions*/
return true;
}
}
return super.dispatchKeyEvent(event);
}
在活动级别中重写
dispatchKeyEvent
的正确方式是什么?这些警告行吗?我应该在我的视图的onKeyUp
和onKeyDown
中做相应的更改吗? 最佳答案
试试这个
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if (event.getAction() == KeyEvent.ACTION_UP){
enter();
return true;
}}
return super.dispatchKeyEvent(event);
};