输入法如何请求'updateCursor'事件?

时间:2010-11-10 09:22:43

标签: android android-input-method

我们正在实施自定义输入法服务,我们感兴趣 在接收游标更新事件。的文件 InputMethodSession的updateCursor()说: “当目标输入字段的光标位置时调用此方法 在它的窗口内发生了变化。这通常不会被调用,但会 只有在输入法 的情况下才会报告。。

输入法如何请求此事件?

提前致谢,

安德烈

2 个答案:

答案 0 :(得分:4)

看起来这是未实现的。在TextView实施中,调用updateCursor取决于InputMethodManager.isWatchingCursor,其有用地定义如下:

/**
 * Returns true if the current input method wants to watch the location
 * of the input editor's cursor in its window.
 */
public boolean isWatchingCursor(View view) {
    return false;
}

幸运的是,您可以使用onUpdateSelection检测光标移动,尽管它们将作为文本中的逻辑位置而不是Rect提供给您。

答案 1 :(得分:1)

从API级别21(棒棒糖)有一种方法可以做到:

获得inputConnection后

每次光标位置发生变化时,都会调用onUpdateCursorAnchorInfo