android - 更新到 androidx.appcompat :appcompat:1. 1.0 后的语言更改问题

标签 android configuration locale android-appcompat

最新链接app-compat这是1.1.0 .

将我的应用程序升级到最新版本后 app-compat我的语言设置在 以下的手机上停止工作API 24 (粗略地说,肯定不适用于 API 21 及以下版本)。

对于 API 24 及更高版本,我使用了 ContextWrapper并设置 locale因此有效。

我的问题是 androidx.appcompat:appcompat:1.1.0是稳定版本为什么它在alpha 中对我有用和 beta与这里的其他版本和我尝试过的问题不同的版本。

  • After updating AppCompat library to appcompat:1.1.0-alpha03 Locale configuration is not working anymore
  • Change Locale not work after migrate to Androidx - 讨论 alpha 和 beta(我正在使用最新的稳定版本 1.1.0 )

  • Should I wait for an official stable version again and downgrade to the last stable version or which is the efficient way to let google know if any(ofcourse, I know to file a bug)?

    最佳答案

    编辑:

    要继续使用 1.1.0 版,请将其添加到您的 attachBaseContext 下方。 :

    Kotlin 解决方案:

    override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
        if (overrideConfiguration != null) {
            val uiMode = overrideConfiguration.uiMode
            overrideConfiguration.setTo(baseContext.resources.configuration)
            overrideConfiguration.uiMode = uiMode
        }
        super.applyOverrideConfiguration(overrideConfiguration)
    }
    

    Java 解决方案:
    @Override
    public void applyOverrideConfiguration(Configuration overrideConfiguration) {
        if (overrideConfiguration != null) {
            int uiMode = overrideConfiguration.uiMode;
            overrideConfiguration.setTo(getBaseContext().getResources().getConfiguration());
            overrideConfiguration.uiMode = uiMode;
        }
        super.applyOverrideConfiguration(overrideConfiguration);
    }
    

    If you don't need to upgrade to the latest appCompat then check the old answer. Else use the solution provided by @0101100101 here.



    旧答案:

    花了几个小时尝试后,才知道这可能是一个错误。

    降级 到最后一个稳定版本,它可以完美运行。
    dependencies {
        implementation 'androidx.appcompat:appcompat:1.0.2'   //************ DO NOT UPGRADE LANGUAGE ISSUE on API 23 and below *******************//
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    ....
    }
    

    同时,我向 Google https://issuetracker.google.com/issues/140880275 提交了一个问题。

    关于android - 更新到 androidx.appcompat :appcompat:1. 1.0 后的语言更改问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57900554/

    相关文章:

    java - 在 onCreate() 中更改文本时出现空指针异常

    android - 如何从外部更改 recyclerview 项目的布局?

    docker - Docker聚集了多个服务实例,每个实例具有不同的配置

    c# - AppSettings.json 用于 ASP.NET Core 中的集成测试

    c++ - 使用 C++17 处理 Unicode 的高效、符合标准的机制是什么?

    html - 带有 HTML 和分隔符的 Android TextView

    android - 如何使用 RxJava/RxAndroid 从 Android 服务更新 UI

    locale - 检测语言环境并更改 url(重定向)以包含语言环境

    java - 遍历属性文件中的 SOAP 请求

    JavaScript:使用 jasmine 进行 toLocaleString() 测试