【发布时间】:2017-12-25 15:05:30
【问题描述】:
InputMethodManager 是一项服务,应用可以使用它与系统键盘进行交互。像EditText 这样的编辑器也使用它来间接通知键盘更改(例如,updateSelection)。
我可以像这样得到InputMethodManager的引用
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
我的问题是这似乎只适用于系统键盘。我可以将InputMethodManager 用于custom in-app keyboard 吗?如果它只是一个孤立的应用程序,我不在乎,但我在一个库中包含一个自定义键盘,它将在许多应用程序中使用。我需要一种标准的方式让编辑与键盘进行交流。
我是否必须编写自己的输入法管理器,或者有没有办法将标准 InputMethodManager 与我的自定义应用内键盘一起使用?
更新
如果无法使用标准输入法管理器,我可以如何实现自己的自定义输入法管理器。
-
InputMethodManager(documentation) (source code) InputMethodinterfaceInputMethodSessioninterface-
KeyboardView.OnKeyboardActionListenerinterface(键盘实现) -
InputMethodService(键盘扩展此)(documentation) (source code)
【问题讨论】:
-
我决定走自己的自定义输入法管理器的路线。我认为无法使用
InputMethodManager系统,因为它涉及手机的安全问题。但是,我添加赏金只是为了确保在我完全放弃这个想法之前。
标签: android keyboard custom-keyboard inputmethodmanager