Android 键盘 InputConnection setSelection 不适用于 unicode?

问题描述

在编辑器中粘贴带有 unicode 的文本时,例如:

?? Please give me an authentic answer buddy.

并且正在做:

getCurrentInputConnection().setSelection(31,43);

所选文本不在正确位置。可能是因为开头的两个特殊的unicode字符?

解决方法

我相信这个功能可以解决这个问题:

public void setSelectionByUnicodePosition(InputConnection inputConnection,String currentString,int start,int end){
        int firstUnicodeposition  = currentString.offsetByCodePoints(0,start);
        int secondUnicodePosition = currentString.offsetByCodePoints(0,end);
        inputConnection.setSelection(firstUnicodeposition,secondUnicodePosition);
    }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...