输入法如何请求“updateCursor”事件?
我们正在实施自定义输入法服务,我们很感兴趣 在接收游标更新事件时。的文档 InputMethodSession 的 updateCursor() 说: "当光标定位到目标输入字段时调用此方法 在其窗口内发生了变化。这通常不会被调用,但会 仅如果输入法请求才报告。”
输入法如何请求此事件?
提前致谢,
Andriy
we are implementing custom input method service and we are interested
in receiving cursor update events. The documentation of
InputMethodSession's updateCursor() says:
"This method is called when cursor location of the target input field
has changed within its window. This is not normally called, but will
only be reported if requested by the input method."
How the input method can request this event?
Thanks in advance,
Andriy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来这还没有实现。在
TextView
实现中,调用updateCursor
的条件是InputMethodManager.isWatchingCursor
,其定义如下:幸运的是,您可以使用 < 检测光标移动code>onUpdateSelection,尽管它们将作为文本中的逻辑位置而不是矩形提供给您。
It looks like this is unimplemented. In the
TextView
implementation, callingupdateCursor
is conditional onInputMethodManager.isWatchingCursor
, which is helpfully defined as follows:Luckily, you can detect cursor movements using
onUpdateSelection
, although they will be given to you as a logical position within the text rather than a Rect.从 API 级别 21 (Lollipop) 开始,有一种方法可以做到这一点:
覆盖
onUpdateCursorAnchorInfo(CursorAnchorInfocursorAnchorInfo)
并调用
inputConnection.requestCursorUpdates(intcursorUpdateMode)
< /p>获得 inputConnection 后。
每次光标位置发生变化时都会调用
onUpdateCursorAnchorInfo
。From API level 21 (Lollipop) there is a way to do it:
Override
onUpdateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo)
and call
inputConnection.requestCursorUpdates(int cursorUpdateMode)
after you got the inputConnection.
The
onUpdateCursorAnchorInfo
will be called every time the cursor's position has changed.