将URL中HTML的文件内容转换为文字设置在一个TextView中。
ImageGetter imageGetter = new ImageGetter(){
@Override
public Drawable getDrawable(String source){
URL url = null;
Drawable drawable = null;
try{
url = new URL(source);
drawable = Drawable.createFromStream(url.openStream(), "");
}catch(Exception e){
e.printStackTrace();
}
return drawable;
}
}
t1.setText(Html.fromHtml(content, imageGetter, null));
解释:1.t1是一个布局文件中的TextView控件
2.content是一个代解析的HTML文件(例如content为HTML文件"content":"
白术近期货源走销顺畅,行情趋升,目前安国市场统个售价13.5-14元/公斤。<\/p>\r\n
<p right\"="" style="font-family: Simsun; font-size: medium;"> 【责任编辑:杨萍 (商陆)】<\/p>")3.imageGetter是解析的图片文件,可以直接设置TextView中。