Android 资源里 Strings.xml的占位符使用

例如:我是%1$s,一个月多少%2$d钱,他身高是%3$.2f米 

在Android Strings.xml中使用

其中%1 代表第一个占位符的value,以此类推

$s 代表它是 字符串(相当于String)

$d 代表 整数型 (int)

$.2f 是浮点数 其中.2 ==x.xx 小数点后面几位

在class中的使用

String stringTest=context.getResources().getString(R.string.a);

String stringResult=String.format(stringTest,"tom",1000,1.78);

System.out.print("stringResult="+stringResult);

输出= 我是tom一个月多少1000钱,他身高是1.78米

你可能感兴趣的:(Android 资源里 Strings.xml的占位符使用)