我使用以下代码从 Android 上的软输入键盘监听 0 - 9 的按键:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_0)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_1)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_2)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_3)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_4)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_5)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_6)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_7)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_8)
{
return super.onKeyDown(keyCode, event);
}
if(keyCode == KeyEvent.KEYCODE_9)
{
Log.d("Keycode", "Got KeyCode 9");
return super.onKeyDown(keyCode, event);
}
return true;
}
当我以以下模式显示软输入键盘时,该代码有效:
但是,当我在以下模式下显示软输入键盘时,它不起作用:
为什么是这样?