如何在TextView中显示双引号(“)符号?


96

我正在尝试在xml文件的文本视图中用双引号显示一些单词。但是它不起作用。请帮助我。

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

任何人都知道解决方案……。

Answers:


190

在中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


6
它适用于strings.xml <string name =“ double_quote”> \“ </ string>,但不适用于layout.xml
Tyler Davis

这个答案是不正确的,因为OP专门询问“在xml文件中的文本视图中用双引号引起来”而不是在strings.xml中。
Patrick

69

使用&quot;符号来解决此硬编码问题:)

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

1
这必须是正确的答,如果你想在布局文件中的符号,而无需使用string.xml
Jaydipsinh砸落

1
您不能使用它的事实strings.xml是一个大问题。
Mike Baxter


10

请尝试

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




1

使用单引号将消息包装起来,并且可以在字符串中使用任意多个双引号。

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

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.