Search code examples
androidandroid-appcompatandroid-textinputlayoutmaterial-components-androidandroid-textinputedittext

Underline, cursor and hint disappeared at TextInputEditText in TextInputLayout on focus


I have an edit profile screen with bunch of TextInputEditTexts. It worked fine before, but now on focus underline, cursor and hint become invisible.

Has anyone faced the same problem?

enter image description here

...

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tilFirstName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@id/ivContactIcon"
        app:layout_constraintEnd_toEndOf="@id/gEnd"
        app:layout_constraintTop_toBottomOf="@id/toolbar"
        android:layout_marginStart="@dimen/margin_32"
        android:layout_marginTop="@dimen/margin_24"
        android:hint="@string/profile_edit_hint_first_name"
        >

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/etFirstName"
            android:layout_height="wrap_content"
            style="@style/FontRoboRegularSizeMFontPrimaryOneLineMatchWrap"
            tools:text="Oleh"
            android:inputType="textCapWords"
            android:maxLines="1"
            android:nextFocusForward="@id/etLastName"
            android:imeOptions="actionNext"
            />
    </com.google.android.material.textfield.TextInputLayout>

...

UPDATE: After changing background of the root element it's clear that these elements become white. not disappeared.

enter image description here


Solution

  • The default style used by the TextInputLayout is

    <style name="Widget.MaterialComponents.TextInputLayout.FilledBox" parent="Base.Widget.MaterialComponents.TextInputLayout">
        <!-- underline color in FilledBox style -->
        <item name="boxStrokeColor">@color/mtrl_filled_stroke_color</item>
    
        <!-- The color of the label when it is collapsed and the text field is active -->
        <item name="hintTextColor">?attr/colorPrimary</item>
        ....
    </style>
    

    The mtrl_filled_stroke_color is based on the colorOnSurface.

    Check in your theme the colorPrimary and the colorOnSurface values, or use a custom style with the same attributes described above.