如何以编程方式更改android应用程序语言环境/语言运行时

如何以编程方式更改android应用程序语言环境/语言运行时,android,localization,Android,Localization,如何更改android应用程序区域设置/语言运行时/编程方式,最佳实践方式 我也看过其他的解决方案,但它们都被低估了。希望这将是未来的参考。适用于Android=N 我也有同样的问题 很抱歉,updateConfiguration方法在API级别25中已被弃用。请参阅createConfigurationContextConfiguration。没错,我还没有尝试使用这个新函数createConfigurationContext。您可以编写一个自定义上下文包装器,并将其作为基本上下文附加到活动中

如何更改android应用程序区域设置/语言运行时/编程方式,最佳实践方式

我也看过其他的解决方案,但它们都被低估了。希望这将是未来的参考。

适用于Android 对于>=N


我也有同样的问题

很抱歉,updateConfiguration方法在API级别25中已被弃用。请参阅createConfigurationContextConfiguration。没错,我还没有尝试使用这个新函数createConfigurationContext。您可以编写一个自定义上下文包装器,并将其作为基本上下文附加到活动中。这是一个参考点。
Locale locale = new Locale(mLanguageCode);
Locale.setDefault(locale);
Configuration config = mContext.getResources().getConfiguration();
config.locale = locale;
mContext.getResources().updateConfiguration(
    config,
    mContext.getResources().getDisplayMetrics()
);
activity.recreate();
Locale locale = new Locale(mLanguageCode);
Locale.setDefault(locale);
Configuration config = mContext.getResources().getConfiguration();
config.setLocale(locale);
mContext.getResources().updateConfiguration(
    config,
    mContext.getResources().getDisplayMetrics()
);
activity.recreate();