-
<string name="loading">离下班回家还剩%1$s分钟</string>
...
String temp = getResources().getString(R.string.loading);
String timeTip = String.format(temp,38);
结果:离下班回家还剩38分钟
-
<string name="loading">离下班回家还剩%1$3s分钟</string>
...
String temp = getResources().getString(R.string.loading);
String timeTip = String.format(temp,38);
结果:离下班回家还剩 38分钟
注:m设置为3只有1个空格
-
<string name="loading">离下班回家还剩%1$3s分钟</string>
...
String temp = getResources().getString(R.string.loading);
String timeTip = String.format(temp,38);
结果:离下班回家还剩 38分钟
注:m设置为10,有8个空格
-
<string name="loading">离下班回家还剩%1$#4s分钟</string>
...
String temp = getResources().getString(R.string.loading);
String timeTip = String.format(temp,60);
结果:app崩溃,抛出异常信息:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.samson.test/com.samson.test.TestActivity}: java.util.FormatFlagsConversionMismatchException: %s does not support '#'
注:%s不支持设置#
-
<string name="loading">离下班回家还剩%1$4d分钟</string>
...
String temp = getResources().getString(R.string.loading);
String timeTip = String.format(temp,38);
结果:离下班回家还剩 38分钟
注:m设置为4,有2个空格
...