Android 字符串资源 Formatting and Styling

文档

Formatting and Styling

例子:

1
2
3
4
<string name="good_example">This\'ll work</string>
<string name="good_example_2">"This'll also work"</string>
<string name="bad_example">This doesn't work</string>
<!-- Causes a compile error -->
1
2
3
4
5
<string name="good_example">This is a \"good string\".</string>
<string name="bad_example">This is a "bad string".</string>
<!-- Quotes are stripped; displays as: This is a bad string. -->
<string name="bad_example_2">'This is another "bad string".'</string>
<!-- Causes a compile error -->
1
2
3
4
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

Resources res = getResources();
String text = res.getString(R.string.welcome_messages, username, mailCount);