Android:Strings.xml 中带有 Double 值的字符串格式

Dol*_*rma 5 android

我需要使用格式化程序创建一个字符串以在应用程序中显示一些双精度值。我不清楚如何编码。这是我所拥有的:

<string name="diseaseMessage">You have %s message, Unread %s</string>
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?  
error: Unexpected end tag string    strings.xml /TSMS Pro/res/values    line 70 Android AAPT Problem
Run Code Online (Sandbox Code Playgroud)

Mr.*_*mas 5

<string name="diseaseMessage">You have %1$s message, Unread %2$s</string>
Run Code Online (Sandbox Code Playgroud)

Android 文档:

格式化字符串

如果您需要使用String.format(String, Object...)格式化您的字符串,那么您可以通过将您的格式参数放在字符串资源中来实现。例如,使用以下资源:

<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
Run Code Online (Sandbox Code Playgroud)

在本例中,格式字符串有两个参数:%1$s 是一个字符串,%2$d 是一个十进制数。您可以使用应用程序中的参数格式化字符串,如下所示:

Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
Run Code Online (Sandbox Code Playgroud)