Android TextView supports LinkiFy and Href tags

I want to set the text in a textview that contains href tags as well as regular http links. For example, text like this "please <a href=/'http://google.com' target='_blank'>click here</a>. or visit http://yahoo.com ".

The problem is that I cannot set both properties together. If I set Html.fromHtml to text, the link with the href tag will be highlighted. But the Linkfy property does not work for "http://yahoo.com" and vice versa. Is there a default property to include href tags and regular links in a TextView.

Thanks,

+6
source share
2 answers

I could not find it myself, since I was working with a similar situation with HREF and phone numbers ; instead of something better, I am currently using a special REGEX to call Linkfiy.addLinks. Calling Linkify.addLinks with the mask "also removes all existing Spannable URLSpans" that were created by Html.fromHtml. See Link Documentation .

0
source

If it is possible to use the mx control label (the spark does not support this anymore), you can use htmlText, as in the following example:

 import mx.controls.Label //class need to be imported var textview:Label = new Label(); textview.htmlText = "please <a href=/'http://google.com' target='_blank'>click here</a>. or visit http://yahoo.com"; yourItemContainer.addElement(textview); 

That should work. But I do not know if a regular label can be used.

-3
source

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


All Articles