I want to make a TextView with a link. I made it with combination of html and bit of java:
// used to enable link navigation on TextView
setMovementMethod(LinkMovementMethod.getInstance())
// TextView with link
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:linksClickable="true"
android:text="@string/link"/>
// @string/link
<string name="link">Test <a href="#">link</a></string>
However there is still one issue, the space before actual link text is underlined like this:
Why is that and how could it be fixed?
In Android, the most common way to show a text is by TextView element. The whole text in the TextView is easy to make clickable implementing the onClick attribute or by setting an onClickListener to the TextView.
To call linkify in android, we have to call linkify. addLinks(), in that method we have to pass textview and LinkifyMask. Linkify. WEB_URLS: It going make URL as web url, when user click on it, it going to send url to default web browsers.
addLinks is used to add links to a TextView, Android uses a class known as LinkMovementMethod for highlighting links when they're focused and dispatching Intents when they're clicked.
// @string/link
<string name="link1">Test <a href="#">link</a></string>
You can use the white space in xml as string use  
. XML won't take white space as it is. it will trim the white space before setting it. So use  
instead of single white space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With