如何处理在 EditText 上键入时按返回键的事件?当显示虚拟键盘并且用户按回时,它会被隐藏.我想处理这个事件,但是在 EditText 中设置 OnKeyListener 并没有帮助.
How can I handle the event of pressing back key while typing on an EditText? When the virtual keyboard is shown and the user presses back, it gets hidden. I want to handle this event, but setting an OnKeyListener in the EditText does not help.
谢谢 Reno.它可能似乎有效,但我设法以不同的方式解决它.
Thank you Reno. It probably seems to work, but I managed to solve it differently.
我覆盖了 EditText 的 onKeyPreIme(int keyCode, KeyEvent event).此方法拦截 IME 上的按键.=D
I overrode EditText's onKeyPreIme(int keyCode, KeyEvent event). This method intercepts keypresses on the IME. =D
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK &&
event.getAction() == KeyEvent.ACTION_UP) {
// do your stuff
return false;
}
return super.dispatchKeyEvent(event);
}
这篇关于取回 EditText 上的关键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!