简体   繁体   中英

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):

示例截图

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.

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM