Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText underline below text property

I would like to change the blue colour below the edit text, i don't know what property it is.

I tried using a different background colour for it but it didn't work.

I've attached an image below:

enter image description here

like image 337
AndroidEnthusiast Avatar asked Jan 31 '14 12:01

AndroidEnthusiast


People also ask

How to set underline in EditText in android?

Custom Subject Modification UnderlineAdd an EditText to activity_main. xml, and add the android:theme="@style/MyEditText" attribute. The effect is as follows: As you can see, the color of the cursor and underline will be changed, but the spacing will remain.

How do you underline text on Android?

You can define the underlined text in an Android layout XML using a String Resouce XML file. In a string res file you have to use an HTML underline tag <u> </u> .

How can I remove underline from text in Android?

There is a really practical and easy way to remove underline for a text. And that is: textview. setPaintFlags(View. INVISIBLE);


3 Answers

It's actually fairly easy to set the underline color of an EditText programmatically (just one line of code).

To set the color:

editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN); 

To remove the color:

editText.getBackground().clearColorFilter(); 

Note: when the EditText has focus on, the color you set won't take effect, instead, it has a focus color.

API Reference:

Drawable#setColorFilter

Drawable#clearColorFilter

like image 135
Jing Li Avatar answered Sep 23 '22 22:09

Jing Li


Use android:backgroundTint="" in your EditText xml layout.

For api<21 you can use AppCompatEditText from support library thenapp:backgroundTint=""

like image 32
Soheil Setayeshi Avatar answered Sep 25 '22 22:09

Soheil Setayeshi


You have to use a different background image, not color, for each state of the EditText (focus, enabled, activated).

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

In the site above, you can get images from a lot of components in the Holo theme. Just select "EditText" and the color you want. You can see a preview at the bottom of the page.

Download the .zip file, and copy paste the resources in your project (images and the XML).

if your XML is named: apptheme_edit_text_holo_light.xml (or something similar):

  1. Go to your XML "styles.xml" and add the custom EditText style:

    <style name="EditTextCustomHolo" parent="android:Widget.EditText">
       <item name="android:background">@drawable/apptheme_edit_text_holo_light</item>
       <item name="android:textColor">#ffffff</item>
    </style>
    
  2. Just do this in your EditText:

    <EditText
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       style="@style/EditTextCustomHolo"/>
    

And that's it, I hope it helps you.

like image 38
Akariuz Avatar answered Sep 22 '22 22:09

Akariuz