2012-04-29 42 views
1

全部,HTML格式在TextView中

我在我的字符串資源xml文件中有以下內容。

<?xml version="1.0" encoding="utf-8"?> <resources> 

<string name="hello">Hello World, ProDroid_Android!</string> 
<string name="app_name">ProDroid_Android-CH3-Resources</string> 

<plurals name ="eggs_in_A_basket"> 
    <item quantity ="one"> There is 1 egg</item> 
    <item quantity = "other"> There are %d eggs</item> 

</plurals> 
<string name="simple_string">simple string</string> 
<string name="quoted_string">"Quoted String 'xyz' string"</string> 
<string name="double_quoted_string">\"Double Quoted String\""\";</string> 
<string name="java_format_string">Hello %2$s Java format String. %1$s again.</string> 

<string name="tagged_string">Hello <b><i> Slanted Android.</i></b>, You are bold</string> 

當我去把tagged_string到一個TextView與HTML格式不與它的格式顯示。不過,如果我剪切並粘貼你好傾斜的Android。,你是大膽的,並手動將它放入.setText它的工作,或者如果我靜態地在我的佈局xml文件中設置它。然而,使用下面的Java代碼它不工作(所有你看到的是未格式化的文本):

//HTML 
     TextView t6 = (TextView) findViewById(R.id.textView6); 

     t6.setText(Html.fromHtml(ProDroid_Android.this.getString(R.string.tagged_string))); 

任何幫助,將不勝感激。

THX

+0

請顯示你的logcat .. – NovusMobile 2012-04-30 11:31:53

回答

1

如果格式化XML格式的文本沒有必要使用Html.formatHtml(...)

試試這個:

t6.setText(getString(R.string.tagged_string); 

編輯: 嗯......這樣的工作對我來說罰款,我試圖正好你的字符串。 也許你的項目需要一個乾淨的(項目>清潔...)

如果這沒有幫助: 我發現了另一個question。也許那裏的答案可以解決你的問題

+0

沒有這樣做沒有。任何其他想法?我正在運行API 10。 – 2012-04-29 15:09:06