How to Change Line Color in Edittext

How to change line color in EditText

This is the best tool that you can use for all views and its FREE many thanks to @Jérôme Van Der Linden.

The Android Holo Colors Generator allows you to easily create Android components such as EditText or spinner with your own colours for your Android application. It will generate all necessary nine patch assets plus associated XML drawable and styles which you can copy straight into your project.

http://android-holo-colors.com/

UPDATE 1

This domain seems expired but the project is an open source you can find here

https://github.com/jeromevdl/android-holo-colors

try it

this image put in the background of EditText

android:background="@drawable/textfield_activated"

Sample Image


UPDATE 2

For API 21 or higher, you can use android:backgroundTint

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
android:backgroundTint="@android:color/holo_red_light" />

Update 3
Now We have with back support AppCompatEditText

Note: We need to use app:backgroundTint instead of android:backgroundTint

<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
app:backgroundTint="@color/blue_gray_light" />

Update 4
AndroidX version

  <androidx.appcompat.widget.AppCompatEditText

app:backgroundTint="@color/blue_gray_light" />

Change Line Color of EditText - Android

You need to set background source for an edit text.

  1. Generate it http://android-holo-colors.com/
  2. Than you can apply generated drawable as background like android:background="@drawable/my_theme_edit_text" for the custom EditText. Or you can set that background in your app theme - you will find example in .zip file from that site

Changing EditText bottom line color with appcompat v7

Finally, I have found a solution. It simply consists of overriding the value for colorControlActivated, colorControlHighlight and colorControlNormal in your app theme definition and not your edittext style. Then, think to use this theme for whatever activity you desire. Below is an example:

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">@color/accent</item>
<item name="colorControlHighlight">@color/accent</item>
</style>

Programmatically changing underline color of EditText

You need to set the backgroundTintList (or supportBackgroundTintList) on the EditText to an instance of ColorStateList containing only the color you wish to change the tint to. An easy way to do this in a backwards-compatible way looks like this:

ColorStateList colorStateList = ColorStateList.valueOf(color);
editText.setSupportBackgroundTintList(colorStateList);

This will give the EditText the desired underline color.

How to change textinput edittext underline color when unfocused?

I had a similar problem aswell, where my focused hint color was different compared to unfocused.

The solution that worked for me is the following:

In your text input layout set android:textColorHint="@color/your_unfocused_color" for unfocused color and app:hintTextColor="@color/your_focused_color" for focused, this also changes the underline stroke color, when the state is focused.

For the underline, you need to set app:boxStrokeColor="@color/underline_colors"

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/focused" android:state_enabled="true" />
<item android:color="@color/focused" android:state_hovered="true" />
<item android:color="@color/focused" android:state_focused="true" />
<item android:color="@color/unfocused" />
</selector>

How to change bottom line color of EditText?

Use :

editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);

Note : getColor() method is deprecated for API level 23. So you need to use Contextcompat to get color.



Related Topics



Leave a reply



Submit