As far as I know, fromhtml of Android can recognize a few HTML tags like " <b>
, <i>
, <u>
, <a>
" and so on. But I cannot convince how to render following HTML code for android with fromhtml attribute.
String html = "<code style='background:#f0f0f0'>this is code</code><pre>this is pre</pre><table><tr><td>this is table</td></tr></table>";
textView.setText(Html.fromHtml(html);
It's only for TextView , not for WebView . any solution will be appreciated.
Android doesn't support HTML in this way see Html.java for supported tags. I'd extend TextView and parse/draw it myself.
现在我改变了主意,使用WebView而不是TextView在android中显示所有HTML标签。
webview.loadDataWithBaseURL(null, HTMLString, "text/html", "UTF-8", null);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.