Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout - Change floating label hint color if EditText is not empty and not focused

Res state - hint color black, good
enter image description here

Focused state, empty - hint color gray, good
enter image description here

Focused state, not empty - hint color gray, good
enter image description here

Res state, not empty - hint color black, not good, should be gray
enter image description here

How to change hint color if editText is not empty and not focused?

This is my current code:

<android.support.design.widget.TextInputLayout
    android:id="@+id/email"
    style="@style/AuthInput"
    android:layout_marginTop="32dp"
    android:hint="@string/hint_email"
    android:inputType="textEmailAddress"
    android:theme="@style/AuthInput"
    app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout">

    <EditText
        android:id="@+id/edit_email"
        style="@style/AuthEditText"
        android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>

and styles:

<style name="AuthInput">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColorHint">@color/black</item>
    <item name="android:paddingLeft">0dp</item>
</style>

<style name="TextAppearance.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/inputHintActive</item>
</style>
like image 359
RexHunt Avatar asked May 17 '17 08:05

RexHunt


People also ask

How do I get rid of floating hint in TextInputLayout?

Floating Hints are enabled by default in a TextInputLayout. To disable it we need to add the following attribute inside the tag : app:hintEnabled="false" . The below xml code is from the activity_main. xml layout and has three EditText fields.


1 Answers

Try below code:

<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/black</item>
    <item name="colorControlNormal">@color/transparant</item>
    <item name="colorControlHighlight">@color/black</item>
    <item name="colorControlActivated">@color/transparant</item>
    <item name="android:textColorHint">@color/black</item> // set grey color for hint
</style>

Screenshot

like image 124
Bhavnik Avatar answered Sep 24 '22 03:09

Bhavnik