android - AutoLink link square brackets of URL in TextView -
i have url: https://<site name>/pallavi/[songs.pk]%2002%20.mp3
i have text view, property: android:autolink="all"
if set text text view, text view highlights portion preceding [. looks this:
https://< site name >/pallavi/[songs.pk]%2002%20.mp3
what want is, whole link should highlighted like:
https://< site name >/pallavi/[songs.pk]%2002%20.mp3
what have tried till now:
used < pre > tag , html.fromhtml, doesn't seem work! (i don't know if < pre > supported in android though.)
used jsoup.parser. doesn't seem work me.
update have tried answer too: https://stackoverflow.com/a/12376115/1320263
please let me know if issue android text view's linkall property not consider parenthesis valid character or not? if supported, how hyperlink too?
also note: text(or link) have written in question sample text. in reality, getting block of text, difficult identify hyper link starts , ends. also, number of links present in block un-known. hence cannot use < href = "" >
thing...
if 1 else happens have same issue, following solution worked me:
pattern pattern = pattern.compile("(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))"); spannablestring spannable = new spannablestring(html); matcher matcher = pattern.matcher(spannable); // create activityspans each match while (matcher.find()) spannable.setspan(new activityspan(matcher.group()), matcher.start(), matcher.end(), spannable.span_exclusive_exclusive); // create new textview these spans , enable clickable links mtxteventdescription.settext(spannable);
Comments
Post a Comment