Dev*_*mar 2 android android-resources android-app-bundle
我的应用程序中有一个功能,用户可以在运行时从应用程序内部选择各种语言,它运行良好,直到我以 APK 格式在 Play 商店上部署应用程序,但自从我开始以App Bundle 格式部署我的应用程序后它停止工作。默认字符串资源不会被用户选择的资源替换,但是当我从设备的设置选项更改整个设备语言时,我的应用程序将使用来自 Play 商店的新配置资源进行更新,并且一切正常。有什么方法可以强制所有字符串资源与基本 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());
Run Code Online (Sandbox Code Playgroud)
编辑:
PlayCore API 现在支持按需下载另一种语言的字符串:https : //developer.android.com/guide/app-bundle/playcore#lang_resources
我在这里找到了解决方案。从那里复制
目前,您可以通过在 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
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1433 次 |
| 最近记录: |