I am trying to set the underline color of a TextInputEditText
in a TextInputLayout
. When setting colorControlActivated
to the desired color, the cursor changes color but the underline does not respond.
I have tried:
- Creating a style with
colorControlHighlight
,colorControlNormal
, andcolorControlActivated
defined. Setting widget themes both in the layout file and in the manifest. - Setting the background of the input field to a drawable with the underline manually drawn in.
Here is the style defined in values/themes.xml:
<style name="AppTheme.DetailItem" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:colorControlNormal">#ff0000</item>
<item name="android:colorControlHighlight">#0000ff</item>
<item name="android:colorControlActivated">#ff00ff</item>
</style>
And the theme applied:
<com.google.android.material.textfield.TextInputLayout
android:theme="@style/AppTheme.DetailItem"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:errorEnabled="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:enabled="false"
android:maxLines="1"
android:textAppearance="?textAppearanceBody2"
tools:text="Name" />
</com.google.android.material.textfield.TextInputLayout>
I would expect the underline of the TextInputEditText
to change color to colorControlActivated
when focused, and colorControlNormal
when not focused. However, no matter what, the underline color remains black when not focused, and colorPrimary
when focused. However, the cursor does change to colorControlActivated
when the field is focused, so the widget is recognizing the style I have defined, but it is not using the style colors to draw the underline.