我有一个字符串数组,其中使用了%符号。使用%的正确格式是%。当数组中有多个%它给出了这个错误。

 Multiple annotations found at this
 line:
 - error: Multiple substitutions specified in non-positional format;
   did you mean to add the formatted="false" attribute?
 - error: Found tag </item> where </string-array> is expected

当前回答

不是你的问题,而是类似的问题。

如果字符串条目中有多个格式,则不应多次使用“%s”。

别:

<string name="entry">Planned time %s - %s (%s)</string>

做的事:

<string name="entry">Planned time %1$s - %2$s (%3$s)</string>

其他回答

不是你的问题,而是类似的问题。

如果字符串条目中有多个格式,则不应多次使用“%s”。

别:

<string name="entry">Planned time %s - %s (%s)</string>

做的事:

<string name="entry">Planned time %1$s - %2$s (%3$s)</string>

Use

<字符串=“win_percentage”>%d% wins</字符串>

得到

80%作为格式化字符串获胜。

我使用String.format()方法来获取插入的数字,而不是%d。

对于XML解析器,可以使用%%转义%,但是在设备中会显示两次。

要显示一次,请尝试以下格式:\%%

例如

<string name="zone_50">Fat Burning (50\%% to 60\%%)</string> 

显示为 燃烧脂肪(50% - 60%)

根据谷歌官方文档,使用%1$s和%2$s http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling

你好,% 1 $ s !您有%2$d条新消息。

尝试在它前面使用反斜杠,如下所示:

\%