android - 在 Android 中转义多个 “%” 字符

标签 android xml escaping arrays

我有一个条目的野兽(归结为重现效果的合理最低限度):

<item>100% foo 40%bar</item>

产生这些错误:

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

添加 formatted="false"不会改变任何事情。

<item>100&#37; foo 40&#37;bar</item>

导致相同的错误消息。 WTH?

<item>100% foo 40bar</item>
<item>100 foo 40%bar</item>
<item>100% foo 40%</item>

一切都会好起来的。 用\% 转义它会被忽略,导致同样的错误。 %% 不会导致错误,但我会得到 %%。

最佳答案

%是 XML 中的保留字符,如 < , > , ETC。 使用%%对于每个 %您在字符串资源中使用。

关于android - 在 Android 中转义多个 “%” 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9386411/

相关文章:

powershell - 我可以在 PowerShell 'string' 中使用单引号吗?

java - 为 Android 创建 GUI 的具体过程是什么?

android - CalendarView 需要很多时间来显示

android - 改造 2 : upload image to server and get strange response

python - XML 搜索 python

Ruby 1.9.3 向 URI.escape 添加不安全字符

java - 如何在java中将rgb颜色转换为int

xml - 为什么 XML::Twig 输出提取的字符串两次?

带冒号的 Java SPLIT : and xml

java - 用java中的非转义等效字符串替换所有转义序列