尝试在 strings.xml 中写入符号“%”

Trying to write a the symbol '%' in strings.xml

我已经尝试了我在 Whosebug 上找到的所有 possible variations 用于编写百分号 (%) 符号的方法,但我的应用程序一直崩溃。

这是我想要的文字:

50.0%
完全的。

这是我在 strings.xml 文件中转义的字符串:

<string name="work_package_percent_complete">%.1f%%\nComplete</string>

我从编译器得到的错误是:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.bechtel.pf.mock, PID: 8252 java.util.UnknownFormatConversionException: Conversion = ' '

这是我打电话的地方String.format:

@JvmStatic
fun formatPercentageText(context: Context, percentage: Float): String {
    return String.format(
        context.resources.getString(
            R.string.work_package_percent_complete,
            percentage
            )
        )

}

好像没有正确转义。

似乎没有理由执行 String.format(),因为只要检索字符串就会自动为我处理格式设置。

所以它变成了:

@JvmStatic
fun formatPercentageText(context: Context, percentage: Float): String {
    return context.resources.getString(
            R.string.work_package_percent_complete,
            percentage
            )
}