我想在用户按下空格键时开始一个活动。我的代码未检测到何时单击空格键。
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.KEYCODE_SPACE) {
Toast.makeText(MainActivity.this, "YOU CLICKED SPACE KEY",
Toast.LENGTH_LONG).show();
return true;
}
Toast.makeText(MainActivity.this, "Didnt work", Toast.LENGTH_SHORT)
.show();
return super.dispatchKeyEvent(e);
};
}