2017-09-18 24 views
0

工作,我得到這個字符串資源:HTML標籤不會在字符串資源

<string name="about_app_text"><b>%1$s</b> some text.\n\n 
     <b>%2$s, text</b>, more text.</string> 

<b>標籤內的文字沒有得到大膽。這是爲什麼?

+1

請添加代碼,你在哪裏轉換成html並將其顯示到文本視圖 – nomag

+0

請通過此鏈接https://developer.android.com/guide/topics/ui/look-and-feel/themes.html –

+0

用[![CDATA]]包裝您的字符串 –

回答

0

你可以試試這個

YourTextview.setText(Html.fromHtml(getResources().getString(R.string. about_app_text))); 

字符串資源:

<string name="about_app_text"><![CDATA[<b>%1$s</b> some text.\n\n 
     <b>%2$s, text</b>, more text.]]></string> 
+0

它似乎有效,但取消了新行字符(\ n)的影響。你知道爲什麼嗎? –

+0

您已退出「字符串」語法並已輸入「html」語法。不要使用\ n作爲新行,請使用

標籤。 – user1541269

1
<string name="about_app_text"><![CDATA[<b>%1$s</b> some text.\n\n 
    <b>%2$s, text</b>, more text.]]></string> 

然後解析爲Spannable

 Spanned spanned = Html.fromHtml(getString(R.string.about_app_text)); 
textView.setText(Spanned);