Search code examples
androidandroid-edittextandroid-themeandroid-stylesandroid-textinputlayout

android - Change color of floating label in TextInputLayout


I try to use the TextInputLayout, I success changing the color of the floating label by following this post, using android:theme="@style/TextLabel" makes floating label color change. However, it only works for Android version 5.0 and above.

For lower version of Android, I use app:hintTextAppearance="@style/TextAppearance.AppCompat". Here is my code:

<style name="EditTextHint" parent="TextAppearance.AppCompat">
    <item name="android:textColor">#bbbbc9</item>
    <item name="android:textColorHint">#bbbbc9</item>
    <item name="android:textSize">11.5sp</item>
</style>

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintTextAppearance="@style/EditTextHint">

        <EditText
            android:id="@+id/fet_input_left"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:paddingTop="7.5dp"
            android:textColor="#595968"
            android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>

The problem is that the color of floating label only change to #bbbbc9 when user tab on the EditText. If user tab on the other EditText, the color is changed to default. Here is the picture:

Correct color
Correct Color: bbbbc9

Error color
Error Colorlt: default color

If you have any suggestions, please let me know. Any ideas would be appreciated.

Thank you in advance!


Solution

  • After doing "on the fly", I try to add android:textColorHint="#bbbbc9" in TextInputLayout and it works. Here is the full code:

    <style name="EditTextHint" parent="TextAppearance.AppCompat">
        <item name="android:textColor">#bbbbc9</item>
        <item name="android:textColorHint">#bbbbc9</item>
        <item name="android:textSize">11.5sp</item>
    </style>
    
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColotHint="#bbbbc9"
        app:hintTextAppearance="@style/EditTextHint">
    
        <EditText
            android:id="@+id/fet_input_left"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:paddingTop="7.5dp"
            android:textColor="#595968"
            android:textSize="14sp" />
    </android.support.design.widget.TextInputLayout>