当我在 android 中使用 edittext.setError("enter a comment")
时,它工作正常,直到出现键盘建议并且错误被推送到 edittext之上
,之后它不会显示整个错误消息。
为什么要这样做?
最佳答案
setError
Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. If the error is null, the error message and icon will be cleared.
所以当文本被更改时,它应该消失了。我不知道为什么这不会发生在你的情况下。
当错误消息为空时,它也应该被清除,所以一个技巧可能是:
edittext = (EditText)findViewById(R.id.foo); // add below this line
edittext.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){
if(s != null && s.length() > 0 && edittext.getErrorMessage() != null) {
edittext.setErrorMessage(null);
}
}
});
关于android - 键盘建议导致部分 Android EditText.setError() 消息不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7747268/