图像中的TextView的HTML不正确显示 [英] Image in html of TextView not being displayed properly

查看:142
本文介绍了图像中的TextView的HTML不正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView,我放到一个AlertDialog是这样的:

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);

我的alert_quickhints_html是:

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>.../>

我在入资产价值有文件夹的icon.png。当我执行这个code,我可以在那里的图标应该出现的地方看到一个小红场。不知怎的,似乎图标不正确呈现。它是用透明PNG。有没有人有这样的想法?

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?

推荐答案

Android的的TextView 只支持有限的一组HTML标记和&LT; IMG&GT; 绝对不是其中之一。如果你真的需要在对话框中显示复杂的HTML,使用的WebView

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
其实我错了,&LT; IMG&GT; 是有点儿支持。使用<一个href=\"http://developer.android.com/reference/android/text/Html.html#fromHtml%28java.lang.String,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler%29\"相对=nofollow> Html.fromHtml(字符串源,Html.ImageGetter imageGetter,Html.TagHandler tagHandler)方法(注imageGetter参数),为您提供HTML图像。

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.

这篇关于图像中的TextView的HTML不正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆