首页 > 解决方案 > 视图卡在 InputConnection 的 `commitText` 方法上

问题描述

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

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

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

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

标签: androidkeyboardinputconnection

解决方案


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

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

推荐阅读