安卓开发中strings.xml的使用

为了使用方便也是为了代码规范化,我们都将文字信息放在res-values-strings.xml中,

因为开发中需要用到将文字的换行,百度了一下,可以将文字段信息直接在strings.xml文件中换行

具体做法

<string name="aaaa">属性 攻击力+60点,并附带18\%%吸血效果 使用 3秒内普通攻击附带84\%%吸血效果,冷却时间50秒。</string>

我们看到其中 就是换行符,

需要注意的是在文字段信息中,想要输出%号可不是直接打一个百分比号,否则会出现错误

1 Description    Resource    Path    Location    Type
2 error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?    strings.xml    /群雄/res/values    line 16    Android AAPT Problem
1 Description    Resource    Path    Location    Type
2 error: Unexpected end tag string    strings.xml    /群雄/res/values    line 16    Android AAPT Problem

出现这两种错误,正确的做法就是在想要输出的%号之间加一个\% ,即\%%

原文地址:https://www.cnblogs.com/xqxacm/p/4357997.html