In Android development, you often encounter situations in which you need to switch between different languages. Language differences mean that dynamic switching of characters in different languages and dynamic switching of different layouts are required.
This is a very simple feature for Android:
First, in the res create other languages corresponding to the value, layout and other folders, such as the addition of English and Vietnamese version, named such as Value-en-us, Value-vi, layout-en-us, Layout-vi.
The naming rules can be found online, value-en-us, en in English, US for the United States. The country is not written. The Vietnamese version can be fully written as LAYOUT-VI-VN.
So, there are several sets of the same name, with the same ID, but the content properties are different from the multi-version layout.
Then, write the code.
Import Java.util.Locale;
Locale locale;
String language = Locale.getdefault (). GetLanguage ();
if (language.equals ("en")) {
...
}
Can be used in the OnClick event of the switching language:
Case *:
locale = Locale.english;
Or: locale = new locale ("VI", "VN"); Viet Nam
Restart Change language:
private void Changelanguage (locale locale) {
try {
Iactivitymanager am = Activitymanagernative.getdefault ();
Configuration config = am.getconfiguration ();
Config.locale = locale;
Config.usersetlocale = true;
Am.updateconfiguration (config);
} catch (RemoteException e) {log.e (TAG, e.tostring ()); } }
This completes the Code section.
Finally, change the compilation section configuration file to add language support:
/build/target/product directory, language_full.mk|language_small.mk see your compilation options using that file, modify Product_locales
In the Full.mk file, there is this fragment: $ (call inherit-product, build/target/product/languages_small.mk), and the latter path is where we want to set it.
The above is excerpted from other blogs,
In fact, in my compilation environment, add VI_VN to Locales_full.mk.