2

I would like to display images (png, gif) stored in a string that has the html tag ( , < im /> ...). Show Html no problem, but the images aren't working. I saw examples on the Internet but only for a string that contains only ONE image without text and more.

description.setText(Html.fromHtml(new.getDescription()));

Example:

"<p>Text before image</p>\r\n<p><img style="max-width: 100%;" src="data:image/gif;base64,R0lGODlhMgA2APQAACgoKDg4ODiQaFCQEHi4IEDYcGiIuIhYKLhoIMAYIPh/></p>"

Thx all for answers.

jere
  • 57
  • 9

1 Answers1

-1

In short, to make this happen, you need use the expanded overload of Html.fromHtml:

description.setText(Html.fromHtml(new.getDescription(), new CustomImageGetter(), null));

And you have to create the CustomImageGetter itself (it implements ImageGetter), and make CustomImageGetter.getDrawable return a drawable constructed from your byte string. It might be easier to do a WebView, or to save the byte string as a resource and use the CustomImageGetter to get that instead.

This question is similar to another stack overflow question: android-TextView setText in Html.fromHtml to display image and text, which can help you set up a CustomImageGetter that will return a drawable from a resource. Then you can start playing around with getting the byte string to work.

Community
  • 1
  • 1
clnoel
  • 22
  • 5