I am using two textview
to display links from database, I managed to change link colors but I want to remove the underline
email.setText(c.getString(5));
website.setText(c.getString(6));
Linkify.addLinks(email, Linkify.ALL);
Linkify.addLinks(website, Linkify.ALL);
Can I do that from XML or Code ?
Underline in android:autoLink can be removed using android:textAllCaps="true" and android:textIsSelectable="false"
You can do it in code by finding and replacing the
URLSpan
instances with versions that don't underline. After you callLinkify.addLinks()
, call the functionstripUnderlines()
pasted below on each of yourTextView
s:This requires a customized version of URLSpan which doesn't enable the TextPaint's "underline" property:
Here is My method
Call It like this
Appcontroller is my application class where i put this method so that i can access it from anywhere
If you are using Textview autolink property and you want to remove underlines you can use it:
First, extend UnderlineSpan and remove underline:
Second, create and instance of NoUnderlineSpan, create a Spannable from the String text and set the span to the spannable:
Reference: http://prog3.com/sbdm/blog/maosidiaoxian/article/details/39156563
UnderlineSpan
already exists, but can only set the underline.Another solution is to add a no underline span on each existing
URLSpan
. Thus the underline state is disabled just before painting. This way you keep yourURLSpan
(possibly custom) classes and all other styles set elsewhere.Here is how you set it without removing the existing URLSpan object: