我在Android Studio中有23个xml文件。并且每个xml文件都有Textview,其值/字符串中包含文本。<string name="long_text1 to 23"
。如果文本没有太多字符,那就没问题了,但是当我粘贴大量文本时,会出现Gradle.build错误。如何插入大量文本,应该在Java文件中编写什么代码?我应该为每个textView创建一个新的字符串吗?谢谢你。
[http://i.stack.imgur.com/duI4a.png][1]
读取第一个错误,其余的是第一个错误的结果,因此可以忽略它们。
没有确切的字符串,很难说出是怎么回事,但是根据错误消息,我猜是这样:您粘贴的长文本包含使APT爆炸的特殊字符。它抱怨“以非位置格式指定了多个替换项”,这意味着您有多个%s
/ %d
/ etc ...这在Android中是不允许的。
<!-- Correct non-positional with single string substitution -->
<string name="formatted_string">Hello %s!</string>
<!-- Correct non-positional with single string substitution -->
<string name="formatted_number">result=%d</string>
<!-- Incorrect non-positional with multiple substitutions -->
<string name="formatted_multi">Hello %s! The result is %d.</string>
<!-- Corrected non-positional to positional with multiple substitutions -->
<string name="formatted_multi_fixed">Hello %1$s! The result is %2$d.</string>
阅读https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html上有关“参数索引”的两章
您可以尝试类似:
<string name="random_string" formatted="false" translatable="false" xml:space="preserve"
tools:ignore="TypographyQuotes,TypographyDashes,TypographyEllipsis,TypographyFractions,TypographyOther"><![CDATA["
Long string with <anything> weird %in %it, "most" of what you put here shou'd be ok...
"]]></string>
但是AAPT仍然有可能不喜欢它。如果字符串很复杂,建议将其放入src/main/assets
或下的文件中,src/main/res/raw
并使用适当的API来加载它们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句