语言环境未在发行包中更新

问题描述

语言环境在发行包中没有更新,但正在调试apk中工作。 我在用 targetSdkVersion 29和 androidx.appcompat:appcompat:1.3.0-alpha02

在MainActivity中

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(LocaleManager.updateResources(base));
}


public class LocaleManager {

public static String TAG = "LocaleManager";
public static String LOCALE_HI = "hi_IN";
public static String LOCALE_EN = "en_US";
private static String lan_str;
private static String country_str;
public static void setlan(String str)
{
    String val[] = str.split("_");
    LocaleManager.lan_str = val[0];
    LocaleManager.country_str = val[1];
}

public static String getlanguage()
{
    return LocaleManager.lan_str+"_"+LocaleManager.country_str;
}

 public static Context updateResources(Context context) {

    if(lan_str == null || country_str == null)
        return context;

    Locale locale = new Locale(lan_str,country_str);
    Locale.setDefault(locale);
    Resources res = context.getResources();
    Configuration config = new Configuration(res.getConfiguration());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        config.setLocale(locale);
        config.locale = locale;
    } else {
        config.locale = locale;
    }
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N){
        context = context.createConfigurationContext(config);
    } else {
        res.updateConfiguration(config,res.getdisplayMetrics());
    }
    return context;
}

}

更改语言后,我正在重新午餐MainActivity,但是语言环境未更新。

解决方法

最后我找到了解决方案 将此添加到应用程序build.gradle的android块中

bundle {
    language {
        enableSplit = false
    }
}
https://www.mmbyte.com/article/55895.html引用的

。 谢谢

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...