1

I'm trying to set the hintTextColor AND the boxStrokeColor of Material Design's textInputLayout into 3 different state of colors, for example:

  • red for when it's disabled (I don't know how to set the boxStrokeColor in disabled state, so please don't mind the screenshot)

enter image description here

  • blue for when it's enabled but unfocused

enter image description here

  • green for when it's enabled AND focused

enter image description here

How can I accomplish this?

For the hintTextColor, I've tried the suggestion made by Gabriele Mariotti in here, but the problem is one of the colors is applied to two different states ([disabled] and [enabled but unfocused]), and I want to differentiate these two.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
LuckMan
  • 85
  • 1
  • 5

1 Answers1

3

You can use a custom style:

<style name="CustomOutlineBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="boxStrokeColor">@color/text_input_layout_stroke_color</item>
    <item name="android:textColorHint">@color/text_color_hint</item>
    <item name="hintTextColor">@color/green</item>
</style>

with the @color/text_color_hint selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:alpha="..." android:color="@color/red" android:state_enabled="false"/>
    <item android:alpha="..." android:color="@color/blue"/>
</selector>

and the @color/text_input_layout_stroke_color selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:alpha="..." android:color="@color/green" android:state_focused="true"/>
    <item android:alpha="..." android:color="@color/green" android:state_hovered="true"/>
    <item android:alpha="..." android:color="@color/red" android:state_enabled="false"/>
    <item android:alpha="..." android:color="@color/blue"/>  <!-- unfocused -->
</selector>

Focused:

enter image description here

Unfocused:

enter image description here

Disabled:

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 1
    Thank you. It was actually just a dumb mistake on my part. Now I'm going to always remember to disable the `TextInputLayout`, not the `TextInputEditText`. :) – LuckMan Oct 31 '20 at 09:21