安卓 Resource 字符串使用 String.format 格式化

首先,在 string.xml 里定义类似于这样的东西

<string name="tv_device_info">当前温度为: %s ℃ 当前电量为 %s %%</string>

然后,在 Java 里这样调用

 binding.tvDeviceInfo.text = String.format(getString(R.string.tv_device_info), 666, 100)

运行结果如图
image

posted @ 2021-09-02 21:55  博麗靈夢  阅读(72)  评论(0编辑  收藏  举报