在我的Android应用程序中,我想要改变默认语言dinamically。我已经实现这个方法:Android - 动态更改语言
public void changeLanguage(String lang) { //lang="it" or "en" for example
myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
{
finish();
startActivity(getIntent());
} else recreate();
}
}, 1);
}
,并在清单中我加入到我的MainActivity这一行:
android:configChanges="locale|orientation"
我也试过这样:
android:configChanges="locale|layoutDirection"
这个解决方案运作良好,但只要屏幕旋转回到默认配置并恢复语言。
我该如何解决此问题?
可能重复(http://stackoverflow.com/questions/2264874/changing-locale-within-the-app-itself) – Lamorak
我已经尝试过他们在那篇文章中提供的解决方案,正如我上面所说的那样,它不起作用。 –