I am trying to create an TextInputEditText whose floating hint color will not change when not focused.
The color of the hint is changing from white to blue ie to the color set through textColorHint
field.
It is only happening when the TextInputEditText is filled and not focused. I want the hint to be white when above the TextInputEditText and blue when inside the box. When the TextInputEditText is not empty and not focused the hint color is turning blue.
TextInputEditText
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="4dp"
android:textColorHint="@color/app_blue"
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/fNameET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/text_input_layout_background"
android:ellipsize="end"
android:hint="First Name"
android:lines="1"
android:maxLines="1"
android:paddingStart="16dp"
android:paddingEnd="16dp" />
</com.google.android.material.textfield.TextInputLayout>
TextAppearance.App.TextInputLayout
<style name="TextAppearance.App.TextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textColor">@android:color/white</item>
</style>
And I want to use xml to do the above task not java.
Add this code into your style.xml file ->
<style name="TextLabelDummy" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="colorAccent">@color/black</item> // Text Color
<item name="android:textColorHint">@color/blue</item> // Hint Color
<item name="colorControlActivated">@color/white</item> //Floating label color
</style>
You can change the parent attribute whatever you want. I've randomly used the "Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
Then call this as theme into you layout file
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayoutNumberDummy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"
android:theme="@style/TextLabelDummy">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/textInputEditTextNumberDummy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/text_mobile" />
</com.google.android.material.textfield.TextInputLayout>
It worked fine on my side. Just check it and let me know about it. Thank you.