我在使用 SwiftKey 完成文本时也遇到了同样的问题。为了解决它,你必须记住一些事情:
- 您必须扩展 BaseInputConnection 并包装原始 webview 的 InputConnection
- 不要使用 InputConnectionWrapper 因为它会导致其他问题
你需要子类化第二种方法:commitText
public boolean commitText(CharSequence text, int newCursorPosition) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
return orig.commitText(text, newCursorPosition);
} else {
// pre-kitkat workaround
boolean res = true;
for (int i = 0; i < text.length(); i++) {
res = orig.commitText(text.subSequence(i, i+1), newCursorPosition);
}
return res;
}
}