【发布时间】:2017-03-24 02:39:20
【问题描述】:
在我的输入法服务中,我试图选择当前光标位置之前的文本。以下是代码sn -p
InputConnection inputConnection = getCurrentInputConnection();
ExtractedText extractedText = inputConnection.getExtractedText(new ExtractedTextRequest(), 0);
inputConnection.setSelection(extractedText.selectionStart-1,extractedText.selectionEnd);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.updateSelection(null, extractedText.selectionStart-1,extractedText.selectionEnd, 0, 0);
这有一个非常不稳定的行为,有时它会选择,有时它只是将光标向后移动一步。
谁能指出我做错了什么?
补充:
由于这个问题已经有一段时间没有得到解答,我想提出一个替代问题。我一直在寻找一些选择文本的替代方法,并在黑客键盘上按 shift 然后按箭头键就可以了,但我无法复制该过程。我尝试将 d-pad 键向下和向上键事件与 meta_shift_on 标志一起发送。
但这不起作用...再次,我做错了什么?
【问题讨论】:
标签: android android-softkeyboard android-input-method