Siavash
Siavash

Reputation: 7853

have to make non-url text in textview to be a link to a website (android)

I have text like this: "by proceeding you agree to our terms of service"

I want "terms of service" to be underlined and link to a certain website. Is there a way to do this in xml? I know about the autolink property, but seems to only work if you want to link a text that actually is the url it self. I want to turn any piece of text into a web hyperlink.

if not possible to do it through xml, what's quickest (yet still correct) way to do it through code?

Thanks

Upvotes: 1

Views: 97

Answers (1)

user3691657
user3691657

Reputation:

Firstly use two textviews and align it side by side. In place of link you can place any web address and apply this snippet on your textview

textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));

Upvotes: 1

Related Questions