Android Allows defining multiple string resource files in res/values
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World!</string> <string name="app_name">App Name</string></resources>
When a resource file is created or modified here, ADT will automatically update R. java and generate a unique identifier, such:
public static final class string {public static final int app_name=0x7f040004;public static final int hello=0x7f040003;}
You can use the resource in the program to identify the string with R. string. hello, and convert it directly to a string using getText (R. string. hello) in the Activity.
Special Format String
Code
<Resources>
<String name = "java_format_string">
Hello % 2 $ s java format string. % 1 $ s again
</String>
<String name = "tagged_string">
Hello <B> <I> Slanted Android </I> </B>, You are bold.
</String>
</Resources>
The special format string here refers to the format string with parameters and the string with HTML tags.
Read operations can be as follows:
Code
// Read a Java format string
String javaFormatString = activity. getString (R. string. java_format_string );
// Convert the formatted string by passing in arguments
String substitutedString = String. format (javaFormatString, "Hello", "Android ")
// Set the output in a text view
TextView. setText (substitutedString );
// Read an html string from the resource and set it in a text view
String htmlTaggedString = activity. getString (R. string. tagged_string );
// Convert it to a text span so that it can be set in a text view
// Android. text. Html class allows painting of "html" strings
// This is strictly an Android class and does not support all html tags
Spanned textSpan = android. text. Html. fromHtml (htmlTaggedString );
// Set it in a text view
TextView. setText (textSpan );
Supports multiple languages
To allow applications to support multiple language interfaces, you do not need to redefine the interface. You only need to add a Language Resource Directory and place the corresponding string resource file, for example, res/values-en, to indicate an English string, res/values-zh-rCN indicates Simplified Chinese res/values-zh-rTW indicates traditional Chinese.
Go to the "Settings" program and select "region and text". You can select the corresponding language for testing.