android - Android 中通过 xml 进行字符串格式化

标签 android xml string-formatting

我有像这样的字符串资源

<string name="my_string">Чек от %1$d до 2000 рублей</string>

我在 TextView 中使用这个字符串并且需要在 View 初始化上设置默认值。所以,我知道我可以用 context.getString(R.string.my_string, 100) 做什么。但是,我想在TextView中做到这一点xml 定义。

有没有办法在 TextView 中使用字符串格式xml?类似的东西

android:text="@string/my_string{100}"

最佳答案

您不能将格式化参数放入 XML 中,只能放入 Java 代码中。

参见this question

关于android - Android 中通过 xml 进行字符串格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161316/

相关文章:

java - Firebase For Android Studio - 如何循环访问数据库中的每个项目?

android - Scroll ParentLayout里面包含两个ListView

java - JAXB xjc 生成字段作为元素列表

java - 将xml和java配置与spring混合

wpf - 使用字符串文字在标签上绑定(bind)字符串格式

python - f-strings 与 str.format()

php - 记录没有保存到数据库中使用 php 在 android

android - 无法在 Android 应用程序中访问外部 SD 卡

java - 使用SAX java解析时为"Content is not allowed in trailing section."

python - 在 Python 3.5+ 中将格式字符串作为关键字参数传递的替代方法