How the input method can request 'updateCursor' event?

两盒软妹~` 提交于 2020-01-13 02:52:48

问题


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


回答1:


It looks like this is unimplemented. In the TextView implementation, calling updateCursor is conditional on InputMethodManager.isWatchingCursor, which is helpfully defined as follows:

/**
 * 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;
}

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.




回答2:


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.



来源:https://stackoverflow.com/questions/4142887/how-the-input-method-can-request-updatecursor-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!