tw-S
tw-S

Reputation: 1217

Image in html of TextView not being displayed properly

I have a TextView which I place into an AlertDialog like this:

final TextView textView = new TextView(this);
textView.setText(Html.fromHtml(getString(R.string.alert_quickhints_html)));     
alert.setView(textView);

My alert_quickhints_html is:

  <string name="alert_quickhints_html"><![CDATA[<p><b>Time correction</b><br/>Some text</p>                                     
  <p><img src = "file:///android_asset/icon.png"><b>Report summary</b><br/>Bla bla</p>.../>

I have icon.png in my assests folder. When I execute this code I can see a little red square at the place where the icon should appear. Somehow it seems the icon is not rendered correctly. It's a PNG with transparency. Does anyone have an idea on this?

Upvotes: 2

Views: 2034

Answers (1)

Konstantin Burov
Konstantin Burov

Reputation: 69238

Android TextView supports only limited set of HTML tags and <img> is definitely not one of them. If you really need to show complex html within a dialog, use WebView.

UPD Actually I was wrong, <img> is kinda supported. Use Html.fromHtml(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler) method (note imageGetter parameter), to supply images for your html.

Upvotes: 2

Related Questions