开发者

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

I'm trying to display some words in double quotes in TextView in an XML file, but it's not working.

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

Does any开发者_如何学编程one know a solution for this?


In the strings.xml, you can simply escape special characters (eg double quotes) with a backslash :

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

But in views xml (eg layout.xml), you have to use HTML character entities (like &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


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

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


use escape characters. To display double quote use \"

Your code will be

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


Please try

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


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 there scroll down to C/C++/Java source code


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


If you have a double-quote in your string, you must escape it (\"). Surrounding the string with single-quotes does not work.

In strings.xml

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

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


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


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜