java - Android - Image in TextView via Html.fromHtml? -
i want display image textview in android , thought possible html.fromhtml()
. found different tutorials image local resource. possible when have url image? if yes, can give me example?
i have solution that. put following code add smiles in text view.
private static final factory spannablefactory = spannable.factory .getinstance(); private static final map<pattern, integer> emoticons = new hashmap<pattern, integer>(); static { addpattern(emoticons, ":)", r.drawable.happy); addpattern(emoticons, ":(", r.drawable.sad); addpattern(emoticons, ":d", r.drawable.very_happy); // ...as many pattern want. make sure have images in drawable directory } private static void addpattern(map<pattern, integer> map, string smile, int resource) { map.put(pattern.compile(pattern.quote(smile)), resource); } public static boolean addsmiles(context context, spannable spannable) { boolean haschanges = false; (entry<pattern, integer> entry : emoticons.entryset()) { matcher matcher = entry.getkey().matcher(spannable); while (matcher.find()) { boolean set = true; (imagespan span : spannable.getspans(matcher.start(), matcher.end(), imagespan.class)) if (spannable.getspanstart(span) >= matcher.start() && spannable.getspanend(span) <= matcher.end()) spannable.removespan(span); else { set = false; break; } if (set) { haschanges = true; spannable.setspan(new imagespan(context, entry.getvalue()), matcher.start(), matcher.end(), spannable.span_exclusive_exclusive); } } } return haschanges; } public static spannable getsmiledtext(context context, charsequence text) { spannable spannable = spannablefactory.newspannable(text); addsmiles(context, spannable); return spannable; }
after doing copy paste, write following code set smiles in text view.
textview.settext(getsmiledtext(activityname.this,"hi :) how you...??? :d :("));