我有一个覆盖了 onKeyDown()
的自定义 View 。当我使用标准的 Android 英语(或意大利语)软键盘时它工作正常,但是当我将设备设置为俄语时,按键事件永远不会到达 onKeyDown()
或 onKeyUp()
(他们从未被调用,我尝试使用断点)。
此外,如果所有 View 都丢弃了该事件,我应该能够从 Activity 的方法中捕获它,但似乎我什至无法做到这一点。请注意, View 是聚焦的,事实上我可以捕捉到方向键的按下。删除/退格俄语软键也被捕获。
我应该如何捕捉俄语字符键事件?
最佳答案
来自KeyEvent文档:
As soft input methods can use multiple and inventive ways of inputting text, there is no guarantee that any key press on a soft keyboard will generate a key event: this is left to the IME's discretion, and in fact sending such events is discouraged. You should never rely on receiving KeyEvents for any key on a soft input method.
就您获得KeyEvent
而言,它违反了 Google 的建议,并且在未来的所有 android 版本中都不受支持。随着时间的推移,这种方法肯定会在更多设备上失效。那么如何捕捉角色呢?
一种选择是使用 TextWatcher .
关于android - 俄语(西里尔文)关键事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18151966/