Sai Korlakunta
Sai Korlakunta

Reputation: 163

how to remove underline for textview in android

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

Upvotes: 16

Views: 31483

Answers (5)

hassan bazai
hassan bazai

Reputation: 459

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" />

Upvotes: -1

MN7272
MN7272

Reputation: 19

<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"

Upvotes: 0

Hossein Seifi
Hossein Seifi

Reputation: 1420

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.

Upvotes: 2

Dany Y
Dany Y

Reputation: 7031

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

Upvotes: 18

Ali Nawaz
Ali Nawaz

Reputation: 2500

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.

Upvotes: 11

Related Questions