2012-12-20 57 views
4

我想顯示html "<html><body><font color=\"black\">In the name of <font color=\"blue\"><b> God</b></font>the compassionate, the merciful</font></body><html>" int TextView。所以我用Html.fromHtml()。但輸出與瀏覽器相比是不同的。android Html.fromHtml()在嵌套文本樣式上無法正常工作

區別在於單詞「God」不會以藍色int TextView出現。

代碼:

textView.setText("<html><body><font color=\"black\">In the name of <font color=\"blue\"><b> God</b></font>the compassionate, the merciful</font></body><html>"); 
+2

請分享您的代碼! –

+0

此外,如果您有任何屏幕截圖與瀏覽器的區別,請分享 – jnthnjns

+0

也可能的移動和瀏覽器輸出截圖。 –

回答

2

Html.fromHtml(String)不支持所有HTML標籤

列表允許HTML標籤:

  • BR
  • p
  • EM
  • b
  • DFN
  • 字體
  • BLOCKQUOTE
  • TT
  • 一個
  • SUP
+1

然後,Question不關於支持哪些標籤。 –

1

試試這樣:

textView.setText(Html.fromHtml("<html><body>In the name of<font color=blue><b> God </b></font>the compassionate, the merciful</body><html>")); 

注:黑色是默認的顏色,所以你不必使用黑色<font>標籤。

如果你想用就完成了標籤,如(例如用於 GRAYBLUE)正道

textView.setText(Html.fromHtml("<html><body><font color=gray>In the name of </font><font color=blue><b> God </b></font><font color=gray>the compassionate, the merciful</font></body><html>")); 
相關問題