2011-06-21 85 views
68

我想顯示在雙引號中的一些話,在文本視圖中的XML文件,但它不工作。請幫助我。如何顯示雙引號(「)符號的一個TextView?

<TextView 
    style="@style/TextStyle" 
    android:text="message "quote string 1" and "quote string 2" end message" 
    android:id="@+id/lblAboutPara3" 
    android:autoLink="web"/>  

任何人知道這個解決方案.............

回答

125

strings.xml,你可以簡單地轉義特殊字符(例如雙引號)用反斜槓:

"message \"quote string 1\" and \"quote string 2\" end message" 

但在視圖xml中(例如layout.xml),你必須使用HTML字符實體(如&quot;):

"message &quot;quote string 1&quot; and &quot;quote string 2&quot; end message" 

欲瞭解更多信息,請訪問http://developer.android.com/guide/topics/resources/string-resource.html

+0

與上面相同的答案 – Shah

+0

對我不起作用 – moatist

+0

這不起作用 –

11

使用escape characters。要顯示雙引號使用\"

您的代碼將是

android:text="message \"quote string 1\" and "quote string 2\" end message" 
+0

是的,這是寫 – Shah

8

請嘗試

<TextView 
style="@style/TextStyle" 
android:text='message \"quote string 1\" and \"quote string 2\" end message' 
android:id="@+id/lblAboutPara3" 
android:autoLink="web"/> 
3
<TextView 
style="@style/TextStyle" 
android:text='message "quote string 1" and "quote string 2" end message' 
android:id="@+id/lblAboutPara3" 
android:autoLink="web"/> 
60

使用&quot;符號來解決這個問題的硬編碼:)

android:text="message &quot;quote string 1&quot;" 
+0

爲我工作謝謝 –

+1

這必須是正確的,如果你想在佈局文件中**「**符號而不使用** string.xml **。 –

+1

你是HERO :) –

4
TextView.setText(Html.fromHtml("&ldquo; " + "YOUR TEXT" + " &rdquo;"));