我使用以下方法覆盖了我的应用的语言环境:
Locale locale = new Locale("ca");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
但似乎getRelativeTimeSpanString
不适用于应用程序上下文,而是使用系统区域设置。
您的解决方案几乎是正确的。
但是,由于字符串是从系统资源加载的,因此您必须更新系统资源的配置。以下是我的工作:
Configuration configuration = new Configuration(Resources.getSystem().getConfiguration());
configuration.locale = Locale.GERMANY; // or whichever locale you desire
Resources.getSystem().updateConfiguration(configuration, null);
(注:从Jelly Bean MR1开始,建议使用
configuration.setLocale(Locale.GERMANY);
更改语言环境,而不是直接设置成员。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句