Android的本地化 [英] Android Localization
问题描述
以下code是改变应用程序的语言环境到spainish它在某些设备工作正常,但在某些设备上它enalrging(缩放)在应用程序的意见。任何一个可以给予解决?
配置配置= getResources()getConfiguration()。
区域设置区域设置=新的语言环境(ES,es_ES); //更改为不同的区域设置比你的设备
config.locale =区域;
Locale.setDefault(区域);
getBaseContext()getResources()updateConfiguration(配置,getResources()getDisplayMetrics()。)。;
Log.i(onSelected ..,Locale.getDefault()getCountry());
startActivity(新意图(getApplicationContext(),HomePage.class));
完();
我用这个方法时,我必须使用不同的语言:
1)设置INT所有的语言都支持。 2)使用的基本功能设置默认语言环境。 3)使用功能,推出不同的语言。
这是例子:
2)
公共静态无效setDefaultLocale(上下文的背景下,字符串的语言环境)
{
区域设置appLoc =新区域(区域);
Locale.setDefault(appLoc);
配置的AppConfig =新配置();
appConfig.locale = appLoc;
context.getResources()。updateConfiguration(AppConfig的,context.getResources()
.getDisplayMetrics());
}
其中,locale按照 ISO 639-1
1)
私立语言myLanguage;
公共枚举语言
{
空,西班牙语,英语,加泰罗尼亚语
}
3)
私人无效launchApplication(int语言)
{
//设置语言
开关(语言)
{
情况1:
//西班牙语
setDefaultLocale(getApplicationContext(),ES);
myLanguage = Language.Spanish;
打破;
案例2:
// 英语
setDefaultLocale(getApplicationContext(),恩);
myLanguage = Language.English;
打破;
默认:
//加泰罗尼亚
setDefaultLocale(getApplicationContext(),CA);
myLanguage = Language.Catalan;
打破;
}
意向意图=新的意图(这一点,MyActivity.class);
startActivityForResult(意向,2);
//完成的活动时,与其他活动的回报
完();
}
然后,调用launchApplication(INT选择);且必须的工作!
the following code is for changing app locale into spainish its working fine in some device ,but in some devices it enalrging(zooming)the views in the app. can any one give the solution?
Configuration config = getResources().getConfiguration();
Locale locale = new Locale("es", "es_ES"); // change this to a different Locale than your device
config.locale = locale;
Locale.setDefault(locale);
getBaseContext().getResources().updateConfiguration(config, getResources().getDisplayMetrics());
Log.i("onSelected..", Locale.getDefault().getCountry());
startActivity(new Intent(getApplicationContext(), HomePage.class));
finish();
I use this method when i have to use different languages:
1) Set a int for all the languages supported. 2) Use a basic function to set Default Locale. 3) Use a function to launch in different languages.
This is the example:
2)
public static void setDefaultLocale(Context context,String locale)
{
Locale appLoc = new Locale(locale);
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
context.getResources().updateConfiguration(appConfig, context.getResources()
.getDisplayMetrics());
}
where locale follow the ISO 639-1
1)
private Language myLanguage;
public enum Language
{
Null,Spanish,English,Catalan
}
3)
private void launchApplication(int language)
{
// Set Language
switch (language)
{
case 1:
// Español
setDefaultLocale(getApplicationContext(),"es");
myLanguage = Language.Spanish;
break;
case 2:
// English
setDefaultLocale(getApplicationContext(),"en");
myLanguage = Language.English;
break;
default:
// Catalan
setDefaultLocale(getApplicationContext(),"ca");
myLanguage = Language.Catalan;
break;
}
Intent intent = new Intent(this, MyActivity.class);
startActivityForResult(intent, 2);
// Finish the Activity when return from the other Activity
finish();
}
Then, call launchApplication(int selected); and must be work!
这篇关于Android的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!