androidandroid-stylesandroid-textinputlayout

Change underline color and floating hint color of TextInputLayout


I'm using the above property in my TextInputLayout theme to make the underline color of the TextInputLayout green when activated.

      <item name="colorControlActivated">#27e905</item>

Its works fine and I get the following result

enter image description here

But as you can see colorControlActivated also affects the floating hint color. I need a different color for floating hint. Is there any way t do so?


Solution

  • add these styles in styles.xml

      <style name="textInputLayout.GrayLabel"
        parent="Widget.Design.TextInputLayout">
        <item name="hintTextAppearance">@style/AppTheme.TextFloatLabelAppearance</item>
       </style>
    
        <style name="AppTheme.TextFloatLabelAppearance"         
         parent="TextAppearance.Design.Hint">
        <!-- Floating label appearance here -->
        <item name="android:textColor">@color/YOUR_COLOR</item>
        <item name="android:textSize">@dimen/YOUR_TEXT_SIZE</item>
    </style>
    

    and use it like this:-

            <android.support.design.widget.TextInputLayout
                style="@style/textInputLayout.GrayLabel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dimen_8dp">