引用:http://woshao.com/article/697693b8b65e11e0a18f000c29fa3b3a/
在TextView中显示HTML内容的方法如下所示:
1 TextView description=(TextView)findViewById(R.id.description);
2 description.setText(Html.fromHtml(item.getDescription()));
如果HTML中有图片的话,显示出来的图片会被一个小框取代,那么怎么样才能看到图片呢?查看了一下API,
android.text.Html还还有 另一个方法:
Html.fromHtml(String source,ImageGetter imageGetter,TagHandler tagHandler)
例:
ImageGetter imgGetter = new Html.ImageGetter() { |
02 |
public Drawable getDrawable(String source) { |
03 |
Drawable drawable = null ; |
04 |
Log.d( "Image Path" , source); |
07 |
url = new URL(source); |
08 |
drawable = Drawable.createFromStream(url.openStream(), "" ); |
09 |
} catch (Exception e) { |
12 |
drawable.setBounds( 0 , 0 , drawable.getIntrinsicWidth(), drawable |
13 |
.getIntrinsicHeight()); |
18 |
TextView description=(TextView)findViewById(R.id.description); |
19 |
description.setText(Html.fromHtml(item.getDescription(),imgGetter, null )); |