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

我们正在实现自定义输入法服务,我们感兴趣 在接收游标更新事件。的文件 InputMethodSession的updateCursor()说: “当目标输入字段的光标位置时调用此方法 在它的窗口内发生了变化。这通常不会被调用,但会 只有在输入法要求时才会报告。“ 输入法如何请求此事件? 提前致谢, 舍甫琴科     
已邀请:
看起来这是未实现的。在
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提供给您。     
从API级别21(棒棒糖)有一种方法可以做到: 覆盖
onUpdateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo)
并致电
inputConnection.requestCursorUpdates(int cursorUpdateMode)
获得inputConnection后。 每次光标位置改变时都会调用
onUpdateCursorAnchorInfo
。     

要回复问题请先登录注册