2

I have TextView and it has URL. And I am using AutoLine="web" in XML layout.

Most of them work fine but there is a problem among some of them.

For instance, If there are two different URLs below,

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoLink="web"
    android:text="http://sykwon.blog.me/" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoLink="web"
    android:text="http://sy_kwon.blog.me/" />

Then the URL which doesn't have 'underscore' works fine, but the URL which has 'underscore' doesn't work well.

Normal operation is like there should be 'underline' under the URL, but it's not.

Since the 'underline', the link works.

I want to make it work both of them. Then what is the solution?

Anybody helps me plz.

Take care.

SY Kwon
  • 159
  • 1
  • 2
  • 13
  • possible duplicate of [Remove underline from links in TextView - Android](http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android) – harveyslash Jul 21 '14 at 13:20

1 Answers1

1

The underscore isn't considered as the valid part of any url and you can remove it:

The way to remove underlines from hyperlinks -

Spannable s = (Spannable) Html.fromHtml(content);
for (URLSpan u: s.getSpans(0, s.length(), URLSpan.class)) {
    s.setSpan(new UnderlineSpan() {
        public void updateDrawState(TextPaint tp) {
            tp.setUnderlineText(false);
        }
    }, s.getSpanStart(u), s.getSpanEnd(u), 0);
}
tv.setText(s);

Refer - how-to-create-textview-link-without-underscore-in-android.

Community
  • 1
  • 1
sjain
  • 23,126
  • 28
  • 107
  • 185