前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Multiple substitutions specified in non-positional format

Multiple substitutions specified in non-positional format

作者头像
ppjun
发布2018-09-05 12:07:20
5.4K1
发布2018-09-05 12:07:20
举报
文章被收录于专栏:ppjun专栏ppjun专栏ppjun专栏

as3.0以上在gradle.properties使用android.enableAapt2=true,as就会提示将要过期了,请设置成 android.enableAapt2=false。当我设置成false啦,这时候编译出错误。

Multiple substitutions specified in non-positional format; did you mean to add the formatted="false"

就是当你的string.xml上含有要格式的字符串比如

<string name="time_picker">%s时</string>

这时候会提示上述错误,因为sdk采用了更加严格的aapt编译,正确的用法如下

If you need to format your strings using String.format(String, Object...) , then you can do so by putting your format arguments in the string resource. For example, with the following resource:


In this example, the format string has two arguments: %1$s is a string and %2$d is a decimal number. You can format the string with arguements from your application like this:


 <string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

解决方法:

之前我们用的%s 改为%1$s,如果在一个字符串有两个%s,%s。现在要改为%1$s,%2$s,重新编译没ok了。

拓展

如果字符串含有%,而不需要格式化可以有三种方法解决

  1. 加上formatted="false"
<string name="time_picker" formatted="false">%s时</string>
  1. 用两个%%
<string name="time_picker">%%s时</string>
  1. 用转义字符\
<string name="time_picker" >\%s时</string>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.08.24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 拓展
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档