TextInputLayout set collapsed hint color

There are so many ways to try changing the TextInputLayout collapsed hint color that you can get crazy by just trying all of them. And besides that, there is not even one working as expected. Recently I raised an issue to Google about this and here is the working answer:

Hi, to change the color of the collapsed hint you need set the attribute hintTextColor in your style. (android:textColorHint controls the color of the expanded hint). So you’ll want to have:
<item name=”android:textColorHint”>@color/yellow_60</item>
<item name=”hintTextColor”>@color/blue_60</item>

Also, I see you’re setting android:theme to your style, but you probably want to be setting style=”@style/TextInputLayoutAppearance” instead.

So having a style like this one:

<style name="TextInputLayoutAppearance" 
    parent="Widget.MaterialComponents.TextInputLayout.FilledBox"> 
    <item name="hintTextColor">@color/blue_60</item> 
</style>

You can simply set it on your TextInputLayout and it will change the hint text color:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/ti_whatever"
    style="@style/TextInputLayoutAppearance"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/ten_grid_units"
    android:labelFor="@+id/editText"
    app:error="@{model.firstNameErrorTextMessage}"
    app:errorEnabled="@{model.isErrorEnabledForFirstName}"
    android:paddingStart="@dimen/two_grid_units"
    android:paddingEnd="@dimen/two_grid_units">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/firstName"
        style="@style/MyEditText"
        android:inputType="textPersonName|textCapSentences"
        android:text="@{model.firstNameText}"
        tools:hint="First name"
        tools:text="First name" />

</com.google.android.material.textfield.TextInputLayout>

You may also like...