How can I change the background color of the hint text of TextInputLayout

Viewed 3757

I am programming a view of TextInputLayout

My style.xml is :

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="MyTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
        <item name="boxStrokeColor">@color/colorPrimary</item>
        <item name="hintTextColor">@color/colorPrimary</item>
        <item name="boxBackgroundColor">@android:color/white</item>
        <item name="boxStrokeWidth">2dp</item>
    </style>
</resources>

My color overrides in color.xml are:

<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#c2261a</color>

My TextInput Layout is:

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/weightInput"
        style="@style/MyTextInputLayoutStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:hint="@string/hint_weight"
        app:errorEnabled="true"
        app:helperTextEnabled="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewTitle">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:imeOptions="actionDone"
            android:importantForAutofill="no"
            android:inputType="numberDecimal"
            android:maxLength="5"
            android:maxLines="1"
            android:singleLine="true"
            android:textAlignment="center"
            android:textColor="@color/colorPrimary" />

    </com.google.android.material.textfield.TextInputLayout>

And the final result is

final result

As we can see the background color of the hint text is transparent. How can I find that view.

I tried that style without success:

My style.xml is :

<resources>

  <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="HintText" parent="TextAppearance.Design.Hint">
        <item name="android:textColor">@color/colorPrimary</item>
        <item name="android:background">@android:color/white</item>
    </style>

    <style name="MyTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
        <item name="boxStrokeColor">@color/colorPrimary</item>
        <item name="hintTextColor">@color/colorPrimary</item>
        <item name="hintTextAppearance">@style/HintText</item>
        <item name="boxBackgroundColor">@android:color/white</item>
        <item name="boxStrokeWidth">2dp</item>
    </style>
</resources>
3 Answers

Its Works for me.. I wish its also works for you..

<EditText
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:textSize="14sp" 
    android:hint="Add Your Text Watermark"
    android:textColorHint="@color/yellowcolor" // this line can change hint text color
    android:textColor="@color/yellowcolor"
    android:fontFamily="@font/inter_light"
    android:textAlignment="center"/>

This is to change the line color of edit text.

android:backgroundTint="@color/colorPrimaryDark"

sample code:

<com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@color/colorPrimaryDark"
                    android:imeOptions="actionNext"
                    tools:text="Full name" />
Related