Luong Truong
Luong Truong

Reputation: 2153

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!

Upvotes: 0

Views: 5410

Answers (3)

Kiran Tiwari
Kiran Tiwari

Reputation: 31

This worked for me; Make a custom style as;

<style name="TextFloatLabelAppearance" parent="TextAppearance.Design.Hint">
        <!-- Floating label appearance here -->
        <item name="android:textColor">@color/colorLightGrey</item>

    </style>

And use ;

<android.support.design.widget.TextInputLayout
                        android:id="@+id/store_til"
                        app:hintTextAppearance="@style/TextFloatLabelAppearance"
                        android:textColorHint="@color/colorWhite"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <AutoCompleteTextView
                            android:id="@+id/editText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:textColor="@color/colorWhite"
                            android:hint="@string/your_string">
                        </AutoCompleteTextView>

This is what I did to change the floating text to a custom color.

Upvotes: 0

Luong Truong
Luong Truong

Reputation: 2153

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>

Upvotes: 1

SoMan Tony
SoMan Tony

Reputation: 1

Do you have open two style.xml? one is style.xml while another is style-21.xml ? in style-21.xml, it is used for android-21 / android 5.0 or above original one is for lower support

Upvotes: 0

Related Questions