Android Kotlin 不要连接使用 setText 显示的测试。使用带占位符的资源字符串

Android Kotlin Do not concatenate test displayed with setText. Use resource string with placeholders

还有“无法翻译 setText 中的字符串文字”

现在有关于此的帖子,但似乎对我没有任何帮助。或者需要一个适当的解释。 字符串资源的使用方法 收到警告

 pTxt.text = "Total : $ $price"

这里,价格是一个值

如果使用这个

pTxt.setText(R.string.displayPriceMsg, price)

报错

尝试了 String.format() 但给出了垃圾值。

在strings.xml

中有这个
<string name="displayPriceMsg">Total : $ %1$d</string>

您必须将格式参数传递给 getString 方法:

pTxt.text = context.getString(R.string.displayPriceMsg, price)