How can I change the colour of the error message that can be set to appear below the text field in a TextInputLayout
(via setError(...)
– see error
I needed to do this dynamically. Using reflection:
public static void setErrorTextColor(TextInputLayout textInputLayout, int color) {
try {
Field fErrorView = TextInputLayout.class.getDeclaredField("mErrorView");
fErrorView.setAccessible(true);
TextView mErrorView = (TextView) fErrorView.get(textInputLayout);
Field fCurTextColor = TextView.class.getDeclaredField("mCurTextColor");
fCurTextColor.setAccessible(true);
fCurTextColor.set(mErrorView, color);
} catch (Exception e) {
e.printStackTrace();
}
}
You will need to call textInputLayout.setErrorEnabled(true)
before invoking the above method for this to work.