Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change color of TextinputLayout's edittext underline android [duplicate]

Tags:

android

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>
like image 741
keval patel Avatar asked Aug 30 '16 07:08

keval patel


2 Answers

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.

like image 196
RamithDR Avatar answered Nov 03 '22 09:11

RamithDR


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.

like image 39
Amad Yus Avatar answered Nov 03 '22 09:11

Amad Yus