Android TextView displays text as a link

I have a TextView in my application that I want to display text as a link.

I have the line "See Map" and I want to show it as a hyperlink (blue and underlined).

I am trying to do this:

tvSeeMap.setText(getResources().getString(R.string.see_map)); Linkify.addLinks(tvSeeMap, Linkify.ALL); 

but that will not work.

+4
source share
3 answers

I found a workaround

  String tempString = new String(getResources().getString(R.string.see_map)); SpannableString content = new SpannableString(tempString); content.setSpan(new UnderlineSpan(), 0, tempString.length(), 0); tvSeeMap.setText(content); tvSeeMap.setTextColor(getResources().getColor(R.color.blue)); 

Just like that.

+5
source

using

 Linkify.addLinks(tvSeeMap,Linkify.WEB_URLS); 

instead

 Linkify.addLinks(tvSeeMap, Linkify.ALL); 

to show a link to a hyperlink or web link in textView

+2
source

Does the link have the prefix "http: //"? If not, try adding it. Or it may be that the link has no spaces before and after it

0
source

Source: https://habr.com/ru/post/1445129/


All Articles