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"
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.
- Generate it http://android-holo-colors.com/
- Than you can apply generated drawable as background like
android:background="@drawable/my_theme_edit_text"
for the customEditText
. 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
Sharedpreferences and Thread Safety
Event Onclick for a Button in a Custom Notification
How to Open a Fragment on Button Click from a Fragment in Android
How to Change the Font Size of Tabhost in Android
Exporting SQLite Database to CSV File in Android
Authentication Using Facebook at First and Then Google Causes an Error in Firebase for Android
How to Change Text Color of Simple List Item
Audiotrack, Soundpool or Mediaplayer Which Should I Use
Android Support Library Setup with Maven
Erase Bitmap Parts Using Porterduff Mode
How to Start an Activity from Within a Fragment
How to Replicate Android:Editable="False" in Code
Httpurlconnection Worked Fine in Android 2.X But Not in 4.1: No Authentication Challenges Found
Error: Configuration with Name 'Default' Not Found in Android Studio
How to to Check If a User Has Rated Your App on the Google Play
Clear Recent Apps Wipe the Apps Memory and My Receiver Stopped Working