Reputation: 1359
I have a textview like following (Just an example the text is dynamic)
<TextView
android:id="@+id/msgtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="hi visit: www.abc.com or http://www.cde.com or efg.com or www.mywebsite.com or mywebsite.com/privacy.php"
/>
How is it possible to make links from mywebsite.com only clickable.
Means In the above textview www.mywebsite.com and mywebsite.com/privacy.php only be the clickable links.
Any help?
Upvotes: 1
Views: 276
Reputation: 4023
Try
TextView textView= (TextView) findViewById(R.id.msgtext);
textView.setText(Html.fromHtml("hi visit:" +
"<a href=\"http:/www.abc.com">www.abc.com</a> "+"the rest of your text"));
textView.setMovementMethod(LinkMovementMethod.getInstance());
Upvotes: 0
Reputation: 6664
Before you do setText(stuff)
Parse it to find out the indicies start
/end
of where your url is.
Then you will need to use SpannableString
and ClickableSpan
Followed by something like this:
span.setSpan(clickableSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Now go ahead setText
and setMovementMethod
Upvotes: 0
Reputation: 677
you can try something like below.
view.setText(Html.fromHtml("<a href="Your URL">This is a link</a>"));
Upvotes: 1