1

How to set colorControlActivated for TextInputLayout in programmatically ?

because i want to set underline color. and my color is string (#....) not in R.color thanks!

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
ARR.s
  • 769
  • 4
  • 20
  • 39
  • go for this link you will get help , :https://stackoverflow.com/questions/30546430/how-to-change-the-floating-label-color-of-textinputlayout – Rishav Singla May 23 '19 at 06:01
  • Gabriele's answer looks good, but note that `colorControlActivated` is a _theme attribute_, and so you have to _create_ the widget with a theme that has the attribute set. Once the widget is created, there's no way to change that value. – Ben P. Jan 20 '20 at 20:50

1 Answers1

1

With the TextInputLayout included in the Material Components Library you can use the method:

textInputLayout.setBoxStrokeColor(..)

With a FilledBox style which is the default style (Widget.MaterialComponents.TextInputLayout.FilledBox) the underline color is the strokeColor.

In xml you can use app:boxStrokeColor.

enter image description here

You should use a selector. The default value is something like:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="@color/colorPrimary" android:state_focused="true"/>
  <!-- 4% overlay over 42% colorOnSurface -->
  <item android:alpha="0.46" android:color="@color/colorOnSurface" android:state_hovered="true"/>
  <item android:alpha="0.38" android:color="@color/colorOnSurface" android:state_enabled="false"/>
  <item android:alpha="0.42" android:color="@color/colorOnSurface"/>
</selector>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841