就在最近,context.getResources().updateConfiguration()
已在 Android API 25 中弃用,我需要更改用户选择的应用语言。我正在使用这种方法来更改语言
private void setLanguage(String language){
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
con.getApplicationContext().getResources().updateConfiguration(config, null);
prefData.setCurrentLanguage(language);
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
}
但是得到弃用的 api 警告,我刚刚开始 android 开发。因此任何建议都将有助于解决此警告。
最佳答案
我在 Resource
源代码中找到了以下代码。
/**
* Store the newly updated configuration.
*
* @deprecated See {@link android.content.Context#createConfigurationContext(Configuration)}.
*/
@Deprecated
public void updateConfiguration(Configuration config, DisplayMetrics metrics) {
updateConfiguration(config, metrics, null);
}
文档说您应该使用 Context.createConfigurationContext(Configuration)
代替它已被弃用。
关于java - Android context.getResources.updateConfiguration() deprecated 如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54774485/