从应用程序语言(不是系统语言)中选择资源

choose resources from app language (not system language)

我的android应用程序有自己的语言,不能等同于设备系统语言。例如 - MyApp 有 'ru' 语言,但 phone 有 'en' 语言。 我可以用应用程序做 smth 来获取我的应用程序语言环境资源,而不是系统语言吗?

PS - 我通过此代码更改的应用程序语言:

public static void setLocale(String language) {
        Locale locale = new Locale(language);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        SvoApplication.getContext().getResources().updateConfiguration(config,
                                                                       SvoApplication.getContext()
                                                                                     .getResources()
                                                                                     .getDisplayMetrics());
        SharedPreferencesManager.setCurrentLanguage(language);
    }

并且所有从数据库获取的数据都通过应用程序语言的 sharedPref 值本地化

PPS - 我知道我必须使用 strings-en.xml/strings-ru.xml 等。当我更改我的应用程序语言时它起作用了。但是,例如,当我旋转屏幕时 - 所有资源都将更改为系统默认语言

您可以在扩展 Application.class 的 class 中重写 onConfigurationChanged 方法。并设置config.locale同上

public void onConfigurationChanged(Configuration config) {
    super.onConfigurationChanged(config);
        /*here code to set locale*/
}

现在,当您旋转屏幕时,它会正常工作。