Here, we implement two languages, Simplified Chinese and Traditional Chinese.
Recommended two folders in res directory
Values-zh-rcn
Values-zh-rtw
There is a Strings.xml file under two folders.
A string table of two files of the same name, with the same ID, but the language of the content is different.
such as <string name= "Quit_dlg_title" > Tips </string>
<string name= "Quit_dlg_content" > Tired of it! Let's take a break! Remember to come back oh! </string>
<string name= "Quit_dlg_okbtn_title" > Good </string>
<string name= "Quit_dlg_cacelbtn_title" > Point wrong </string>
<string name= "Quit_dlg_title" > Tips </string>
<string name= "Quit_dlg_content" > Tired of it! Let's take a break! Remember to come back oh! </string>
<string name= "Quit_dlg_okbtn_title" > Good </string>
<string name= "Quit_dlg_cacelbtn_title" > a bit wrong </string>
This is a string resource to use for the dialog box.
It's in the program.
String strpackage = Mcontext.getapplication (). Getpackagename (); Resources mRes = mcontext.getresources (); int id = mres.getidentifier ("Quit_dlg_title", "string", strpackage);// The main is this sentence strtitle = mres.getstring (ID);
In this way, the string is taken. And not through
Strtitle = mres.getstring (R.string.quit_dlg_title);
In such a way that you do not need to use the code file at the beginning of the
Import the R file. Because the normal method once the package name changes, the code has to be changed.
The other strings are similar and no longer be discussed.