android 多语言处理

1) 代码中获取系统语言:

Locale.getDefault().getLanguage()  //语言:取到的比如中文为zh,英文为en,日文为ko;
Locale.getDefault().toString()//具体的类别:比如繁体为zh_TW,简体为zh_CN。英文中有en_GB;日文有ko_KR。

2)Xml中使用多语言:

第一步:将应用中的所有需要显示的字符串,如菜单,标题、文本,以及提示信息等都定义到values/strings.xml之中,注意name属性不能有重复

第二步:将应用中的字符串替换成从strings.xml中引用的形式,如 getResources().getString(R.string.appname)

第三步:真正的多语言设置了,需要新建一个xml文件(Eclipse的 File - New - Android xml file),会显示如图画面!

AndroidManifest.xml中:

每一个Activity中都要加: android:configChanges="locale"。

manifest节点中插入节点:
<supports-screens android:smallScreens="true"
	android:normalScreens="true" android:largeScreens="true"
	android:anyDensity="true" />

3)代码中指定运行语言

public void chooseLanguage(Locale locale) {

	Resources resources = getResources();//获得res资源对象

	Configuration config = resources.getConfiguration();//获得设置对象

	DisplayMetrics dm = resources .getDisplayMetrics();//获得屏幕参数:主要是分辨率,像素等。

	config.locale = locale; //语言

	 resources.updateConfiguration(config, dm);

}
原文地址:https://www.cnblogs.com/comsokey/p/androidLanguages.html