webview打开后Android默认语言环境更改

Rav*_*ari 5 multilingual android locale webview

我坚持使用 webview 和 Locale。在我的多语言应用程序中,当用户从应用程序设置更改应用程序语言,然后用户导航到应用程序内的 webview,然后应用程序区域设置更改为英语,这是设备默认语言。

以下是我从设置更改语言的代码 -

private String Locale_English = "en";
private String Locale_RU = "ru";
private void setLanguage(String type){
    Locale locale = new Locale(type);
    Locale.setDefault(locale);
    finish();
}
Run Code Online (Sandbox Code Playgroud)

假设用户选择俄语,在此用户导航到应用程序仪表板和所有屏幕上的语言更改后,但如果用户从左侧菜单打开静态页面,在应用程序中打开 webview,则设备区域设置更改,仪表板上的所有标签更改为英语。

下面是我的基本活动中的代码,它是仪表板活动的父级

 @Override
protected void onStart() {
    super.onStart();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
        mCurrentLocale = getResources().getConfiguration().getLocales().get(0);
    } else{
        //noinspection deprecation
        mCurrentLocale = getResources().getConfiguration().locale;
    }
}

@Override
protected void onRestart() {
    super.onRestart();
    Locale locale = getLocale(this);
    if (!locale.equals(mCurrentLocale)) {
        mCurrentLocale = locale;
        setLocale();
        recreate();
    }
}

private void setLocale() {
    final Resources resources = getResources();
    final Configuration configuration = resources.getConfiguration();
    final Locale locale = getLocale(this);
    if (!configuration.locale.equals(locale)) {
        configuration.setLocale(locale);
        resources.updateConfiguration(configuration, null);
    }
   // Locale locale1 = getLocale(this);;

    Locale locale1= new Locale(getLocaleStr(this));
    Locale.setDefault(locale1);
}

public Locale getLocale(Context context){
    int language = SessionParam.getPrefDataInt(context,"Current_Language");
    String lang = "en";
    switch (language) {
        case 0:
            lang = "en";
            break;
        case 1:
            lang = "ru";
            break;
    }
    return new Locale(lang);
}
Run Code Online (Sandbox Code Playgroud)

我调试了整个流程,问题是在 webview 加载之后,然后用户导航到任何屏幕,然后语言更改为英语。