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

 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

当前回答

试试这个(右):

<string name="content" formatted="false">Great application %s  ☞  %s  ☞  %s \\n\\nGo to download this application %s</string>

其他回答

可以用%%转义xml中的%,但需要在代码中设置文本,而不是在布局xml中设置文本。

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

\%

我的情况有点不同。我从本地化网站生成我自己的XML文件,我不能让lint检查工作而不显示双%%登录设备。我收到了使用百分比符号而不使用String.format的lint错误

我将所有非格式化%符号替换为:\u0025

一个棘手的方法:使用小百分号如下所示

 <string name="zone_50">Fat Burning (50&#65130; to 60&#65130;)</string> 

百分比在维基百科上签名

为了允许应用程序使用资源中的格式化字符串,你应该纠正你的xml。举个例子

<string name="app_name">Your App name, ver.%d</string>

应该用

<string name="app_name">Your App name, ver.%1$d</string>

你可以看到这个细节。