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

 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

当前回答

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

其他回答

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

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

百分比在维基百科上签名

要转义百分比符号,只需要%%

例如:

String.format("%1$d%%", 10)

返回“10%”

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

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

\%

在你的strings.xml文件中,你可以使用任何你想要的Unicode符号。

例如,百分比符号的Unicode数字是0025:

<string name="percent_sign">&#x0025;</string>

您可以在这里看到Unicode符号的综合列表