格式化字串資源

你可以在字串資源中新增萬用字元,並在執行時填充它們:

  1. 編輯 strings.xml

    <string name="my_string">This is %1$s</string>
    
  2. 根據需要格式化字串

    String fun = "fun";
    context.getString(R.string.my_string, fun);