Textview加载 html代码块和 webview加载html代码块对比

本文对比了TextView和WebView在加载HTML代码块时的效果。TextView显示限制较多,如不支持span标签的颜色显示和img图片加载,而WebView则能正常显示复杂HTML内容。因此,对于复杂的HTML段落推荐使用WebView,简单的可以选择TextView,但WebView会增加性能需求。
摘要由CSDN通过智能技术生成

加载方式

TextView
    String textHtml = "<p>aaa</p><p><strong>fafjoa</strong></p><p style=\"text-align: center;\"><span style=\"color: rgb(227, 0, 0);\"><strong>bbb</strong></span></p>";
    String imgHtml = "<img src="http://xxxx.png" />"
    textView1.setText(Html.fromHtml(textHtml ));
	textView2.setText(Html.fromHtml(imgHtml ));
结果

1、span标签无法显示,即字体颜色没加载出来,查看Html.java 源码,可见支持的标签是有限的
2、图片img标签也没有加载出来

private void handleStartTag(String tag, Attributes attributes) {
    if (tag.equalsIgnoreCase("br")) {
        // We don't need to handle this. TagSoup will ensure that there's a </br> for each <br>
        // so we can safely emit the linebreaks when we handle the close tag.
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值