在Android中以编程方式更改语言不适用于从应用程序包格式生成的APK [重复]

问题描述 投票:2回答:1

这个问题在这里已有答案:

我的应用程序中有一个功能,用户可以在运行时从应用程序内部选择各种语言,它工作正常,直到我在APK格式的Play商店中部署应用程序,但它开始停止工作,因为我开始在App Bundle format deplyoing我的应用程序。默认字符串资源不会被用户选择的那个替换,但是当我从设备的设置选项中更改整个设备语言时,我的应用程序会从Play商店中使用新配​​置的资源进行更新,一切正常。有什么方法可以强制执行所有字符串resouces推送基地apk或任何其他我不知道的方式?请帮忙。我用来改变语言的代码是 -

        Locale locale = new Locale(langCode); //langCode is the code of the language user has selected
        Locale.setDefault(locale);

        Resources res = parentContext.getResources();
        Configuration config = res.getConfiguration();
        config.setLocale(locale); // = locale;
        res.updateConfiguration(config, parentContext.getResources().getDisplayMetrics());
android android-resources android-app-bundle
1个回答
3
投票

编辑:

PlayCore API现在支持按需下载另一种语言的字符串:https://developer.android.com/guide/app-bundle/playcore#lang_resources

我找到了解决方案here。从那里复制

目前,您可以通过在build.gradle中添加以下配置来禁用按语言拆分

android {
    bundle {
        language {
            // Specifies that the app bundle should not support
            // configuration APKs for language resources. These
            // resources are instead packaged with each base and
            // dynamic feature APK.
            enableSplit = false
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.