2015年8月13日 星期四

[Problem] How can I write character & in android strings.xml (轉貼)

String Resources
http://developer.android.com/intl/zh-tw/guide/topics/resources/string-resource.html#FormattingAndStyling

Formatting strings

If you need to format your strings using String.format(String, Object...), then you can do so by putting your format arguments in the string resource. For example, with the following resource:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
In this example, the format string has two arguments: %1$s is a string and %2$d is a decimal number. You can format the string with arguments from your application like this:
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);


ASCII Converter
http://www.mikezilla.com/exp0012.html

How can I write character & in android strings.xml
http://stackoverflow.com/questions/3053062/how-can-i-write-character-in-android-strings-xml

Easiest way is to quote or backslash them:
http://stackoverflow.com/questions/10575898/special-chars-as-xml-string-in-android-app

沒有留言:

張貼留言