7

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>
RexHunt
  • 192
  • 3
  • 16

3 Answers3

1

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

Bhavnik
  • 2,020
  • 14
  • 21
0

You can change the hint color by

editText.setHintTextColor(getResources().getColor(R.color.white));

and if you want to clear the focus of your edit text then use

editText.clearFocus();
  • I think your suggestion is for editText hint, but I need for floating hint and if it's possible, not programmatically – RexHunt May 17 '17 at 11:53
0

Change your TextInputLayout style

Your TextInputLayout

<android.support.design.widget.TextInputLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:theme="@style/TextLabel">

    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/edit_id"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="hintText"/>

</android.support.design.widget.TextInputLayout>

Your TextInputLayout style chnage color according to your test

<style name="TextLabel" parent="TextAppearance.AppCompat">
    <!-- Hint color and label color in FALSE state -->
    <item name="android:textColorHint">@color/colorBlack</item>

    <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="colorControlNormal">@color/colorPrimaryDark</item>
    <item name="colorControlActivated">@color/colorGray</item>
</style>
MilapTank
  • 9,988
  • 7
  • 38
  • 53