Remove underline from interactive email in text form
I am working on an Android application where I put mail in text in textView
and it is viewable. I want to remove the underline from a letter. How to do it?
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/mailnlink"
android:textColor="@color/mltext"
android:textColorLink="@color/link"
android:textStyle="italic"
android:gravity="center"
android:autoLink="email"
android:background="@color/mlb"
android:text="@string/f2"/>
+3
source to share
3 answers
That's how
private void stripUnderlines(TextView textView) {
Spannable s = new SpannableString(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);
}
private class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
0
source to share
You can just add clickable to textView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/mailnlink"
android:textColor="@color/mltext"
android:textColorLink="@color/link"
android:textStyle="italic"
android:gravity="center"
android:clickable="true"
android:background="@color/mlb"
android:text="@string/f2"/>
0
source to share
It worked for me: I added autolink to xml or you can also use link in code.
<TextView
android:id="@+id/mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/mailnlink"
android:textColor="@color/mltext"
android:textColorLink="@color/link"
android:textStyle="italic"
android:gravity="center"
android:background="@color/mlb"
android:autoLink="email"
android:text="@string/f2"
/>
In java file:
TextView mtextView = (TextView) findViewById(R.id.mail);
Spannable sa = (Spannable)mtextView.getText();
for (URLSpan u: sa.getSpans(0, sa.length(), URLSpan.class)) {
sa.setSpan(new UnderlineSpan() {
public void updateDrawState(TextPaint tp) {
tp.setUnderlineText(false);
}
}, sa.getSpanStart(u), sa.getSpanEnd(u), 0);
}ere
0
source to share