为什么我在InputConnection
中有setSelection
,但不是getSelection()
?Android:InputConnection缺少getSelection()方法
我应该只是做一个getTextBeforeCursor(VERY_HIGH_NUMBER, 0)
并计算该字符串的.length()
?
为什么我在InputConnection
中有setSelection
,但不是getSelection()
?Android:InputConnection缺少getSelection()方法
我应该只是做一个getTextBeforeCursor(VERY_HIGH_NUMBER, 0)
并计算该字符串的.length()
?
我同意,这是愚蠢的getSelection()
不存在。你的解决方案可以正常工作,但你必须假设只有一个光标显示,而不是整个选定的文本范围。我还没有想出如何填补这个漏洞。
编辑:哦,当然,:
int selStart = ic.getTextBeforeCursor(HIGH_NUMBER, 0).length();
String sel = ic.getSelectedText();
int selEnd = selStart + (sel==null? 0: sel.length());