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

Vig*_*esh 90 android

我试图在双引号中显示一些单词,在xml文件的Text视图中.但它不起作用.请帮助我.

    <TextView 
    style="@style/TextStyle" 
    android:text="message "quote string 1" and "quote string 2" end message" 
    android:id="@+id/lblAboutPara3" 
    android:autoLink="web"/>    
Run Code Online (Sandbox Code Playgroud)

任何人都知道这个解决方案.............

lou*_*uio 172

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

"message \"quote string 1\" and \"quote string 2\" end message"
Run Code Online (Sandbox Code Playgroud)

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

"message &quot;quote string 1&quot; and &quot;quote string 2&quot; end message"
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请访问http://developer.android.com/guide/topics/resources/string-resource.html

  • 它适用于strings.xml <string name ="double_quote"> \"</ string>但不在layout.xml中 (6认同)

Rog*_*ien 65

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

android:text="message &quot;quote string 1&quot;" 
Run Code Online (Sandbox Code Playgroud)

  • 你不能在`strings.xml` 中使用它是一个大问题。 (3认同)

Sun*_*hoo 14

escape characters.显示双引号使用\"

你的代码将是

android:text="message \"quote string 1\" and "quote string 2\" end message" 
Run Code Online (Sandbox Code Playgroud)


Nik*_*hil 9

请试试

<TextView 
style="@style/TextStyle" 
android:text='message \"quote string 1\" and \"quote string 2\" end message' 
android:id="@+id/lblAboutPara3" 
android:autoLink="web"/> 
Run Code Online (Sandbox Code Playgroud)


Nik*_*rad 7

TextView.setText(Html.fromHtml("&ldquo; " + "YOUR TEXT" + " &rdquo;"));
Run Code Online (Sandbox Code Playgroud)


Jig*_*iya 6

<TextView 
style="@style/TextStyle" 
android:text='message "quote string 1" and "quote string 2" end message' 
android:id="@+id/lblAboutPara3" 
android:autoLink="web"/> 
Run Code Online (Sandbox Code Playgroud)


Dan*_*l F 6

您可以在任何xml文件中使用Unicode

android:text="message \u0022quote string 1\u0022 and \u0022quote string 2\u0022 end message"
Run Code Online (Sandbox Code Playgroud)

http://www.fileformat.info/info/unicode/char/0022/index.htm那里向下滚动到C / C ++ / Java源代码


Sat*_*esh 5

如果您的字符串中有双引号,则必须将其转义(\")。用单引号将字符串括起来是行不通的。

在strings.xml中

<string name="good_example">This is a \"good string\".</string>
Run Code Online (Sandbox Code Playgroud)

来源http : //developer.android.com/guide/topics/resources/string-resource.html