Created
August 29, 2014 10:49
-
-
Save benvium/e2d1897d00d7850fb6dc to your computer and use it in GitHub Desktop.
Remove underlines from TextView links. Based on stackoverflow code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.util.util; | |
import android.text.Spannable; | |
import android.text.TextPaint; | |
import android.text.style.URLSpan; | |
import android.widget.TextView; | |
public class TextViewUtils { | |
private static final String TAG = TextViewUtils.class.getSimpleName(); | |
private static class URLSpanNoUnderline extends URLSpan { | |
public URLSpanNoUnderline(String url) { | |
super(url); | |
} | |
@Override public void updateDrawState(TextPaint ds) { | |
super.updateDrawState(ds); | |
ds.setUnderlineText(false); | |
} | |
} | |
// http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android | |
public static void stripUnderlines(TextView textView) { | |
Spannable s = (Spannable)textView.getText(); | |
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class); | |
for (URLSpan span: spans) { | |
int start = s.getSpanStart(span); | |
int end = s.getSpanEnd(span); | |
s.removeSpan(span); | |
span = new URLSpanNoUnderline(span.getURL()); | |
s.setSpan(span, start, end, 0); | |
} | |
textView.setText(s); | |
} | |
} |
Glad it's still useful after 7 years!
Thanks it works for .Net-Android <3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works perfectly. Thanks