Simple implementation of Android platform multi-language

Source: Internet
Author: User

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.