5

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

输入法怎么能请求这个事件呢?

提前致谢,

安德烈

4

2 回答 2

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 提供给您。

于 2011-04-15T11:45:17.663 回答
1

从 API 级别 21 (Lollipop) 开始,有一种方法可以做到:

在你得到 inputConnection 之后。

onUpdateCursorAnchorInfo每次光标位置改变时都会调用。

于 2015-07-27T15:31:10.313 回答