16

I have seen many questions regarding removing of underline for autolink of textview.

But for me, I am unable to remove underline for normal textview. I set the underline by:

textview.setPaintFlags(nameOnTemplateTextview.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
Sai Korlakunta
  • 163
  • 1
  • 1
  • 5

5 Answers5

18

You can try

 textview.setPaintFlags(textview.getPaintFlags() & (~ Paint.UNDERLINE_TEXT_FLAG));

or more broadly just set,

textview.setPaintFlags(0) but the first option is more exact

Dany Y
  • 6,833
  • 6
  • 46
  • 83
11

Here is technique you can try to remove underline from any textview or edit text using the given below example code snippet

<TextView
    android:id="@+id/et"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:layout_marginBottom="10dp"
    android:hint="This is first EditText"
    android:fontFamily="sans-serif-light"
    android:background="@null"
    />

Use of the attribute

android:background="@null"

you can remove underline from textview or edit text

You can also try putting transparent color to the background to remove underline beneath a textview.

Ali Nawaz
  • 2,016
  • 20
  • 30
2

Maybe it's too late to answer this good question but I share my experience; perhaps it might be helpful for some one.

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

It works perfect for me.

Hossein Seifi
  • 1,380
  • 11
  • 29
0
<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="120px"
    android:autoLink="all"
    android:background="#00FFFFFF"
    android:fontFamily="sans-serif-light"
    android:gravity="center"
    android:linksClickable="false"
    android:longClickable="false"
    android:textSize="30sp" />

If you have an underline problem, use this code in textview

android: autoLink = "all"
MN7272
  • 19
  • 1
  • 5
0

I tried this way, it worked.

Just add android:background="@null" this line of code into your EditText xml.

See the example:

<EditText
           android:id="@+id/txt_search_field"
           android:lines="1"
           android:background="@null"
           android:layout_width="match_parent"
           android:layout_height="wrap_content" />
hassan bazai
  • 424
  • 6
  • 9