Android:InputConnection 缺少 getSelection() 方法

标签 android inputconnection

为什么我在 InputConnection 中有一个 setSelection , 但不是 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());

关于Android:InputConnection 缺少 getSelection() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3652198/

相关文章:

android - 在 ActionBar 中获取 Switch 实例

android - TextInputLayout 轮廓提示颜色

java - Android 未报告的异常 IOException 错误

Flutter:非事件InputConnection上的getTextBeforeCursor

java - 如何找到光标的位置以在编辑文本中从该位置选择文本?

android - 通过 Android 中的自定义键盘在 EditText 上设置撰写文本

android - 如何使用android应用程序控制在linux PC上运行的程序?

android - 位置 vs GeoPoint vs 1E6 vs 充电

android - 如何为自定义 Android View 实现提取文本

flutter - D/输入连接适配器(3218) : The input method toggled cursor monitoring on