动态设置语言字符串源

Dynamic set language string source

在Android动态设置语言字符串源中可以吗?

示例:我在应用程序中有 2 种语言资源,现在我需要强制一个布局文件,在这里我想使用例如英语资源,但系统和 UI 等必须保持默认语言。我只想为一个 xml 文件而不是整个系统设置语言资源。这可能吗?或者任何想法。谢谢

使用它来动态更改语言:

Locale locale = new Locale("en_US"); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);

您可以从 here.

中获取国家代码列表

使用这个

Resources res = context.getResources(); // Change locale settings in the app.
 DisplayMetrics dm = res.getDisplayMetrics();
 android.content.res.Configuration conf = res.getConfiguration();
 conf.locale = new Locale(language_code.toLowerCase());
 res.updateConfiguration(conf, dm);