Given the following HTML:
<p>This is text and this is an image <img src="http://www.example.com/image.jpg" />.</p>
Is it possible to make the image render? When using this snippet: mContentText.setText(Html.fromHtml(text));, I get a cyan box with black borders, leading me to believe that a TextView has some idea of what an img tag is.
If you have a look at the documentation for
Html.fromHtml(text)you’ll see it says:If you don’t want to do this replacement yourself you can use the other
Html.fromHtml()method which takes anHtml.TagHandlerand anHtml.ImageGetteras arguments as well as the text to parse.In your case you could parse
nullas for theHtml.TagHandlerbut you’d need to implement your ownHtml.ImageGetteras there isn’t a default implementation.However, the problem you’re going to have is that the
Html.ImageGetterneeds to run synchronously and if you’re downloading images from the web you’ll probably want to do that asynchronously. If you can add any images you want to display as resources in your application the yourImageGetterimplementation becomes a lot simpler. You could get away with something like:You’d probably want to figure out something smarter for mapping source strings to resource IDs though.