在TextView中的文本中转义“”

时间:2011-08-19 07:21:31

标签: android

我有一个textView,我正在粘贴s字符串作为文本,我有一些“双引号字符”我怎样才能逃避这些字符。

2 个答案:

答案 0 :(得分:14)

反斜杠双引号在XML布局中不起作用。您应该使用HTML代码( quot ),如下所示:

<TextView android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:text="Here goes my &quot;escaped&quot; text!" />

上面的代码将显示一个包含以下内容的TextView:

  

这是我的“转载”文字!

XML有5 of these predifined entities

&quot;   "
&amp;    &
&apos;   '
&lt;     <
&gt;     >

答案 1 :(得分:3)

只需使用String类的replace方法:http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replace(char,%20char

对你使用类似的东西String然后将这个String传递给TextView:

myString.replace("\"", "");