Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to underline an EditText

I am having some problems to underline an EditText in AndroidStudio.

This is what I am looking for (this is just a photo, not my real text):

example screenshot

But I do not really know any property to do that.

My code right now is really simple. Just the "normal" one:

 <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_margin="16dp"
        android:id="@+id/tx_titulo"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:text="@string/pt_titulo"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:allowUndo="true"
        />

I do not want to underline just the text (in this case "Título"), but the whole PlainText

Does anybody know it? Greets.

like image 520
Mario López Batres Avatar asked Nov 16 '16 21:11

Mario López Batres


Video Answer


2 Answers

It is default, but try to check your styles. Maybe there is a style that will override the style in the whole application. If there is, just remove it

like image 148
Malik Abu Qaoud Avatar answered Sep 18 '22 16:09

Malik Abu Qaoud


To do this programatically, you could find an answer in this post.

To set the underline color:

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

To remove the underline color:

editText.getBackground().clearColorFilter();

To do it from the XML, you could add background property to do the same thing in your layout.xml with any drawable resource as a background by adding:

android:background="@drawable/mydrawable"

If you have a couple of EditText with the same style configuration, to avoid setting the attribute to each EditText, you could override EditText's default attributes, defining a custom style like it is done here.

like image 31
ortisenderos Avatar answered Sep 21 '22 16:09

ortisenderos