从文本观察器更改 imeOptions
Changing imeOptions from a text watcher
我正在尝试从 textwatcher 更改 imeOptions,在检测到编辑文本上的“@”符号时,我需要将其 imeOptions 从 "Go" 更改为 "Done"。请指教
etSample.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if ((charSequence+"").contains("@")){
etSample.setBackgroundColor(Color.BLACK);
etSample.setTextColor(Color.WHITE);
etSample.setImeOptions(EditorInfo.IME_ACTION_NEXT);
etSample.requestFocus();
}else {
etSample.setBackgroundColor(Color.WHITE);
etSample.setTextColor(Color.BLACK);
etSample.setImeOptions(EditorInfo.IME_ACTION_DONE);
etSample.requestFocus();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
这不起作用(它总是显示完成)
尝试将 etSample.requestFocus()
替换为 etSample.setInputType(InputType.TYPE_CLASS_TEXT)
我正在尝试从 textwatcher 更改 imeOptions,在检测到编辑文本上的“@”符号时,我需要将其 imeOptions 从 "Go" 更改为 "Done"。请指教
etSample.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if ((charSequence+"").contains("@")){
etSample.setBackgroundColor(Color.BLACK);
etSample.setTextColor(Color.WHITE);
etSample.setImeOptions(EditorInfo.IME_ACTION_NEXT);
etSample.requestFocus();
}else {
etSample.setBackgroundColor(Color.WHITE);
etSample.setTextColor(Color.BLACK);
etSample.setImeOptions(EditorInfo.IME_ACTION_DONE);
etSample.requestFocus();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
这不起作用(它总是显示完成)
尝试将 etSample.requestFocus()
替换为 etSample.setInputType(InputType.TYPE_CLASS_TEXT)