android - 从文本观察器更改 imeOptions
问题描述
我正在尝试从 textwatcher 更改 imeOptions,在检测到 edittext 上的“@”符号时,我需要将其 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)
推荐阅读
- magento2 - 如何为我们的新 magento 网站保持相同的 url 结构
- c# - 将文件块上传到 SPS 2013 - 行中不存在方法“StartUpload”
- mysql - MySQL - 根据值分配数字
- elasticsearch - 做出像 Quora 这样令人印象深刻的自我暗示的核心部分是什么?
- javascript - 如何打印带有缩进的 HTML 代码?
- azure-devops - 上游 Feed 功能是否会导致计费增加作为副作用?
- c# - DTO(数据传输对象)和数据对象之间是否存在概念差异?
- typescript - 运行用打字稿编写的量角器插件
- sql - 带有 LIKE 的 SELECT 查询失败
- python - 拟合 scipy.linalg.lstsq 时如何考虑数据的不确定性(标准偏差)?