我在编辑模式下有自定义EditText和中文软键盘的问题:我的自定义EditText与texttwatcher:
@Override
public void afterTextChanged(Editable s) {
... // pre composing
// I want to clear current text and append with a new text.
edt.setText(""); // but this line remove 'suggestion state' of soft keyboard
... // transform text (ex: append 'n' to end)
... // finish composing
}
<我>我所说的"建议状态"是指:
-软键盘是中文,当我按下一个键(例如:"h"),软键盘上的建议条会显示。我可以在建议栏中选择一个中文单词来撰写。我>
我怎样才能保持软键盘的当前状态?(或者我可以清除当前文本没有明确的软键盘的"建议状态"?)
在TextView的源代码中阅读后,我看到方法'append':
public void append(CharSequence text, int start, int end) {
if (!(mText instanceof Editable)) {
setText(mText, BufferType.EDITABLE);
}
((Editable) mText).append(text, start, end);
}
'append'方法没有清除'suggestion state'。
所以改成:
...
Editable edtable = edt.getText();
edtable.clear();
edt.setText(edtable, BufferType.EDITABLE);
....