在我的软键盘中,我可以完美地捕捉要删除的事件键,如下所示
public void onKey(int primaryCode, int[] keyCodes) {
if (primaryCode == Keyboard.KEYCODE_DELETE) {
int ccLength = composingContent.length();
if (ccLength > 1) {
composingContent.delete(ccLength - 1, ccLength);
getCurrentInputConnection().setComposingText(composingContent, ccLength - 1);
}
}
}
问题是当设置新的composingContent时,它会附加到旧文本的末尾。它不会清除旧内容。我也用过
getCurrentInputConnection().commitText(composingContent, ccLength - 1);
但这也不能清除以前的任何作曲文本
答案 0 :(得分:0)
InputConnection conn = getCurrentInputConnection();
if (conn != null) {
int ccLength = composingContent.length();
if (ccLength > 1) {
composingContent.delete(ccLength - 1, ccLength);
conn.setSelection(0, ccLength);
conn.setComposingText(composingContent, 1);
}
}