2011-12-24 21 views
2

據我所知,Android的html可以識別一些HTML標籤,如「<b>,<i>,<u>,<a>」等。但我無法說服如何使用fromhtml屬性爲Android呈現以下HTML代碼。android fromhtml無法識別所有HTML標籤

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

這只是爲的TextView,不爲的WebView。任何解決方案將不勝感激。

回答

2

現在我改變了主意,使用WebView而不是TextView來顯示android中的所有HTML標記。

webview.loadDataWithBaseURL(null, HTMLString, "text/html", "UTF-8", null); 
+0

我也覺得這是Android提供的唯一解決方案。我正在嘗試將CS​​S與fromHtml結合使用,並且它似乎是不可能的。 – Aada 2013-03-21 09:29:49

3

Android不支持這種方式的HTML,請參閱Html.java獲取支持的標籤。我會擴展TextView並自己解析/繪製它。

+0

可以顯示樣本編碼作爲答案嗎? – ppshein 2011-12-25 02:33:40