1
我TextInputLayout支持库中有一些错误的Android
我有一个注册表格中,我使用TextWatcher
做验证。我用支持库的TextInputLayout
突出错误
我的问题
当我EditText
我输入不正确的数据,该TextInputLayout
令我EditText
到red
颜色
然后,当我把正确的在我EditText
输入,然后更改focus
到其他领域,仍是第一EditText
是红色不改变正常editext背景
我试过
我试图设置我的EditText
编程到我的自定义绘制的背景,但它给我的其他的外观和感觉(其它颜色)
也试过只改变HintColor
到TextInputLayout
红不使用setError()
方法,仍然没有结果
我的代码
1的方法:给我一些其他颜色的背景
public boolean validateFirstName() {
mFirstName = edFirstName.getText().toString().trim();
if (mFirstName.isEmpty()) {
tiFirstName.setError(mEmptyFields);
edFirstName.requestFocus();
return false;
} else {
tiFirstName.setError(null);
tiFirstName.setErrorEnabled(false);
edFirstName.setBackground(getResources().getDrawable(R.drawable.ed_line_bg));
}
return true;
}
第二个方法:看到任何变化:(
public boolean validateFirstName() {
mFirstName = edFirstName.getText().toString().trim();
if (mFirstName.isEmpty()) {
edFirstName.requestFocus();
changeTextInputLayoutColorToRed(tiFirstName);
return false;
} else {
changeTextInputLayoutColorToNormal(tiFirstName);
edFirstName.setBackground(null);
}
return true;
}
public void changeTextInputLayoutColorToRed(TextInputLayout textInputLayout){
int redColor=getResources().getColor(android.R.color.holo_red_dark);
// textInputLayout.getEditText().setHighlightColor(redColor);
textInputLayout.getEditText().setHintTextColor(redColor);
textInputLayout.setError(mErrorMessage);
textInputLayout.setErrorEnabled(true);
}
public void changeTextInputLayoutColorToNormal(TextInputLayout textInputLayout){
int normalColor=getResources().getColor(R.color.text_color);
//textInputLayout.getEditText().setHighlightColor(normalColor);
textInputLayout.getEditText().setHintTextColor(normalColor);
textInputLayout.setError(null);
textInputLayout.setErrorEnabled(false);
}
看起来几乎与我相似的代码......有什么实际的区别? –
猜猜它是与你的TextWatcher或更改焦点,当你做一些事情。这对我的作品 –
让我试试这个兄弟:) –