0

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!

Community
  • 1
  • 1
Luong Truong
  • 1,953
  • 2
  • 27
  • 46
  • You can refer to here http://stackoverflow.com/questions/30546430/how-to-change-the-floating-label-color-of-textinputlayout – SoMan Tony Jul 26 '16 at 03:04
  • @SoManTony: Thank you for your comment, your link is exactly the same as the post I read. Do you have other suggestions? – Luong Truong Jul 26 '16 at 03:12

3 Answers3

1

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>
Luong Truong
  • 1,953
  • 2
  • 27
  • 46
0

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

  • 1
    or you can try this http://stackoverflow.com/questions/36385055/error-inflating-class-edittext-on-creating-textinputlayout-on-android-4-4-2 to remove parent="TextAppearance.AppCompat" – SoMan Tony Jul 26 '16 at 03:29
  • Welcome to Stack Overflow! This is really a comment, not an answer. With a bit more rep, [you will be able to post comments](//stackoverflow.com/privileges/comment). – Enamul Hassan Jul 26 '16 at 03:45
  • @SoManTony: Thank you again, I find out the solution now :) – Luong Truong Jul 26 '16 at 04:17
0

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.