As per Googles Material Guidelines:
https://material.io/guidelines/components/text-fields.html#text-fields-layout
TextInputLayout hint should be the same color as the Error message:
However it is not like that and when I call setError("My error")
only the underline and the error message show up in red.
How can I change this behavior to account for Google's own guidelines?
here is how you can do it
<android.support.design.widget.TextInputLayout
android:padding="8dp"
android:id="@+id/tilSample"
app:errorTextAppearance="@style/error_appearance"
app:hintTextAppearance="@style/error_appearance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/etSample"
android:layout_margin="8dp"
android:padding="8dp"
android:hint="android"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
style.xml
<style name="error_appearance" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/colorRed</item>
<item name="android:textSize">12sp</item>
</style>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorRed">#f44336</color>
</resources>
EDIT
we can do manipulate the error and hint colours in code also using
tilSample.setErrorTextAppearance(R.style.error_appearance);
tilSample.setHintTextAppearance(R.style.error_appearance);
Now this is default behaviour. To achieve this, just update your support library version to 28+.
implementation 'com.android.support:design:28.0.0'
Here is an example:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/email_layout"
android:textColorHint="@color/gray"
app:errorTextAppearance="@style/TextAppearence.App.TextInputLayout"
app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
<android.support.design.widget.TextInputEditText
android:id="@+id/et_email"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:cursorVisible="true"
android:gravity="center|left|bottom"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:maxLength="50"
android:paddingBottom="10dp"
android:textColor="@color/black_effective"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
Style File:
<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/gray</item>
</style>
Snapshot: