How to display double quotes(") symbol in a TextView?

我试图在一个 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"/>

有人知道怎么解决吗?

112003 次浏览

strings.xml中,您可以简单地用反斜杠转义特殊字符(如双引号) :

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

但是在 views xml (例如 layout.xml)中,必须使用 HTML 字符实体(例如 &quot;) :

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

For more, visit http://developer.android.com/guide/topics/resources/string-resource.html

使用 escape characters。要显示双引号使用 \"

你的代码是

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

请试试

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

Use &quot; symbol to solve this hardcode problem :)

android:text="message &quot;quote string 1&quot;"
TextView.setText(Html.fromHtml("&ldquo; " + "YOUR TEXT" + " &rdquo;"));

如果字符串中有双引号,则必须将其转义为 (\")。用单引号包围字符串不起作用。

在 strings.xml 中

<string name="good_example">This is a \"good string\".</string>

译自: 美国《科学》杂志网站(http://developer.android.com/guide/questions/resources/string-resources. html) http://developer.android.com/guide/topics/resources/string-resource.html

You can use Unicode in any xml file

android:text="message \u0022quote string 1\u0022 and \u0022quote string 2\u0022 end message"

Http://www.fileformat.info/info/unicode/char/0022/index.htm 向下滚动到 < em > C/C + +/Java 源代码

Use single quotes to wrap the message and you can use as many double-quotes as you want inside the string.

android:text='message "quote string 1" and "quote string 2" end message'