小编Cho*_*pta的帖子

android kotlin:将变量插入 strings.xml 条目

我知道可以将局部变量插入到硬编码字符串中,例如

val amount = "10"
findViewById<TextView>(R.id.textView).text = "There are $amount things."
Run Code Online (Sandbox Code Playgroud)

会输出There are 10 things.. 但是,当我尝试在 strings.xml 文件中执行相同的操作时,例如

<resources>
<string name="some_string">There are $amount things.</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
val amount = "10"
findViewById<TextView>(R.id.textView).text = getString(R.string.some_string)
Run Code Online (Sandbox Code Playgroud)

输出是There are $amount things.. 我怎么解决这个问题?

string android text kotlin

0
推荐指数
1
解决办法
2166
查看次数

标签 统计

android ×1

kotlin ×1

string ×1

text ×1