资源字符串的通配

资源字符串的通配

1、在资源文件strings.xml中把需要动态改变的字符换成<xliff:g id="tongpei1">%$s</xliff:g>或<xliff:g id="tongpei1">%$d</xliff:g>

      如果有多处%后加上标志如%1$s、%2$s...

  <string name="conn_data_content">Some <xliff:gid="tongpei1">%$s</xliff:g>internet package. Details with your operator</string>

   <string name="conn_data_content">Some <xliff:gid="tongpei1">%1$s</xliff:g>internet package<xliff:g id="tongpei2">%2$s</xliff:g>. Details with your operator</string>

2、在用到的类中这样写:

      mContext.getString(R.string.conn_data_content,“sdfe”,“aEnd”);

得到的是Some sdfe internet package aEnd . Details with your operator

      

你可能感兴趣的:(android)