我已经本地化了几乎所有的应用程序,只剩下一些异常值。下面是一个例子。如果不创建 2 个单独的 @string 变量,我该如何做到这一点?
builder.setTitle("Version " + getAppVerName() + " Changes");
其中 getAppVerName() =
public String getAppVerName() {
String text;
try {
text = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
text = "Version Not Found";
}
return text;
}
最佳答案
您可以在 strings.xml 中格式化字符串。
<string name="version">Version %1$s Changes</string>
builder.setTitle(getString(R.string.version, getAppVerName()));
关于android - 重构——Android字符串提取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5339773/