8

I am using android design library's TextinputLayout. But couldn't customize the underline color of EditText inside TextinputLayout. Please help.

   <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_pincode"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/input_layout_city"
        android:layout_marginTop="@dimen/_10sdp"
        android:textColorHint="#000000"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">

        <EditText
            android:id="@+id/input_pincode"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Pincode*"
            android:textSize="@dimen/_13sdp" />

    </android.support.design.widget.TextInputLayout>


<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/black</item>
    <item name="android:textSize">@dimen/_13sdp</item>
    <item name="colorControlNormal">@color/black</item>

</style>
Keval Patel
  • 163
  • 1
  • 1
  • 8
  • please share screenshot which helps to know better – Chirag Arora Aug 30 '16 at 07:35
  • 1
    Check this link(http://stackoverflow.com/questions/39219521/when-edittext-is-select-theme-style-does-not-change/39219679#39219679) – MinnuKaAnae Aug 30 '16 at 07:39
  • in your android.support.design.widget.TextInputLayout add android:theme="@style/MyAccount" and in your style – Ashwin H Dec 19 '17 at 06:20
  • The only answer that worked for me after Google-ing SO for an hour is this: https://stackoverflow.com/a/36543554/2413303 – EpicPandaForce Apr 25 '18 at 02:36

3 Answers3

17

Add this style to your styles.xml file :

<style name="TextLabel" parent="TextAppearance.AppCompat">

        <!-- Hint color and label color in FALSE state -->
        <item name="android:textColorHint">#fff</item>
        <item name="android:textSize">20sp</item>

        <!-- Label color in TRUE state and bar color FALSE and TRUE State -->

        <item name="colorAccent">@color/colorPrimaryDark</item>
        <item name="colorControlNormal">#e34b1c</item>
        <item name="colorControlActivated">#e34b1c</item>
</style>

Then add the 'TextLabel' theme to your textinputlayout as below

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_pincode"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/input_layout_city"
        android:layout_marginTop="@dimen/_10sdp"
        android:textColorHint="#000000"
        app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
        android:theme="@style/TextLabel">

...

Play around with the colors you want in the styles.xml.

Krupa Kakkad
  • 857
  • 1
  • 13
  • 28
RamithDR
  • 2,103
  • 2
  • 25
  • 34
11

In your TextAppearence.App.TextInputLayout style, you need to add colorControlActivated and colorControlHighlight.

<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/black</item>
    <item name="android:textSize">@dimen/_13sdp</item>
    <item name="colorControlNormal">@color/black</item>

    //added attributes
    <item name="colorControlActivated">@color/colorPrimary</item> 
    <item name="colorControlHighlight">@color/colorPrimary</item>

</style>

Edited:

You can remove colorControlHighlight. In your case, it is not necessary. colorControlHightlight is used to applied color on ripple, list selected etc.

You can refer to @Gaëtan Maisse answer here.

Community
  • 1
  • 1
Amad Yus
  • 2,856
  • 1
  • 24
  • 32
-1

You should try to change

<color name="colorAccent">#YOURCOLOR</color>

Google Material Design always refer to this color, in order to have the same color for "action" everywhere

Hugo Houyez
  • 470
  • 3
  • 19