1

当用户使用中的键码按下键时,我正在提交文本InputConnection

但是这种方法会挂起视图并在几毫秒后释放

if (getCurrentInputConnection() != null) {
    getCurrentInputConnection().commitText(String.valueOf((char) charCode), 1);
}

我是在做错什么,还是有其他解决方案?

4

2 回答 2

0

为什么不直接从创建一个实例getCurrentInputConnection()

String txt = String.valueOf((char) charCode);
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
    ic.commitText(txt , 1);
}
于 2019-06-19T10:20:09.803 回答
0

不要commitText()在每个按键上使用。

利用

getCurrentInputConnection().setComposingText(mComposingText, 1);

对于所有按键并在按下时提交撰写文本space

提交撰写文本使用

getCurrentInputConnection().finishComposingText();

解决了我的问题

于 2019-07-19T10:29:30.747 回答