在string.xml中存储formattable字符串资源

时间:2014-03-31 15:03:34

标签: android xml android-layout android-resources

如何在res/value/string.xml中存储格式化字符串资源,以便它不会破坏我的R.java?目前我只是拥有以下内容,但它不起作用。

<string name="format_able">This is a formatable string resource with %s and %s as place holders</string>

但是日食没有对它进行红线化。所以花了我几个小时才发现这就是我的R没有被生成的原因。那么如何逃避%s

2 个答案:

答案 0 :(得分:2)

我最后在http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling找到了答案

 <string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

我遗失了1$2$

答案 1 :(得分:0)

尝试更改其HTML编码的“%”字符。例如,要插入“...”,您必须编写代码

"&#8230;"

“%”的代码是

"&#37;"

您可以在此页面中看到它:http://www.ascii.cl/htmlcodes.htm