Sinh Phan
Sinh Phan

Reputation: 1266

Change color bottom line of EditText

I have a EditText in TextInputLayout.

<android.support.design.widget.TextInputLayout
    android:id="@+id/inputTextUser"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" >

    <EditText
        android:id="@+id/userName"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:ems="10"
        android:hint="@string/user_hint"
        android:singleLine="true"
        android:textColor="@color/white"
        android:textSize="16sp" >

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

I want change bottom line color to white, I tried this solution, but It's not work with me:

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorHint">@color/white</item>
        <item name="colorControlNormal">@color/white</item>
        <item name="colorControlActivated">@color/white</item>
        <item name="colorControlHighlight">@color/white</item>
    </style>

    <style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/light_blue_A400</item>
        <item name="android:textSize">12sp</item>
    </style>

Here is image after style theme:

enter image description here enter image description here

Is there any suggestion to change color bottom line when un-focus and focus?

Upvotes: 0

Views: 5347

Answers (4)

The backgroundTint attribute is responsible for the color of the bottom line.

android:backgroundTint="@color/yourColor"

To remove the bottom line, use a transparent color

android:backgroundTint="@android:color/transparent"

Upvotes: 0

Shishram
Shishram

Reputation: 1516

Using java code and using styles you can change this color:-

use this on your

EditTextmUserName.getBackground().setColorFilter(getResources().getColor(R.color.yourWhiteColor), PorterDuff.Mode.SRC_ATOP);

and using styles:- use appcompat theme

<style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryDark">@color/primaryColor</item>
        <item name="colorAccent">@color/primaryColor</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="actionMenuTextColor">@android:color/holo_blue_dark</item>
        <item name="android:actionMenuTextColor">@android:color/holo_blue_dark</item>
        <item name="android:windowBackground">@android:color/white</item>

    </style>

change your colorAccent to white

<item name="colorAccent">@color/whiteColor</item>

Upvotes: 1

Akash Singh
Akash Singh

Reputation: 751

Use this :

mEditText.getBackground().setColorFilter(YOUR_COLOR_HERE, PorterDuff.Mode.SRC_IN);

eg :

mEditText.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_IN)

Upvotes: 7

Aegis
Aegis

Reputation: 5801

You can create a simple style here http://android-holo-colors.com/ this will generate the images need with the different color and the style.xml with the correct attributes.

Upvotes: 0

Related Questions