更新到androidx.appcompat:appcompat:1.1.0后的语言更改问题 [英] Language change issue after updating to androidx.appcompat:appcompat:1.1.0
问题描述
最新的app-compat
的链接为 1.1.0 .
将我的应用程序升级到最新的app-compat
之后,我的语言设置对于 API 24 以下的手机停止运行(肯定不能在API 21及以下版本上运行).
After upgrading my app to the latest app-compat
my language settings stopped working for phones below API 24 (roughly, doesn't work on API 21 and below for sure).
对于API 24及更高版本,我使用了ContextWrapper
并设置了locale
,因此可以使用.
For API 24 and above, I have used the ContextWrapper
and set the locale
hence works.
我的问题是androidx.appcompat:appcompat:1.1.0
是否是稳定版本,为什么它在alpha
和beta
版本中对我有用?我尝试过的问题.
My question is if the androidx.appcompat:appcompat:1.1.0
is the stable version why does it work for me in alpha
and beta
versions unlike the others here & the questions which I have tried.
- 将AppCompat库更新为appcompat之后: 1.1.0-alpha03语言环境配置不再起作用
- 迁移到Androidx后更改语言环境不起作用-讨论alpha和beta(我正在使用最新的稳定版本
1.1.0
)
- After updating AppCompat library to appcompat:1.1.0-alpha03 Locale configuration is not working anymore
- Change Locale not work after migrate to Androidx - Talks about the alpha and beta (I am using the latest stable build
1.1.0
)
我应该再次等待正式的稳定版本并降级到 最后一个稳定的版本,或者这是让Google高效的方法 知道是否有(当然,我知道要提交错误)?
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
下:
To continue using version 1.1.0 add this below your 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);
}
如果您不需要升级到最新的
appCompat
,请检查 旧答案.其他使用@ 0101100101提供的解决方案 此处.
If you don't need to upgrade to the latest
appCompat
then check the old answer. Else use the solution provided by @0101100101 here.
旧答案:
经过数小时的尝试,才知道这可能是一个错误.
After spending hours trying, got to know that it might be a bug.
降级到最新的稳定版本,它可以正常工作.
Downgrade to the last stable version and it works flawlessly.
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
Meanwhile, I have filed an issue with Google https://issuetracker.google.com/issues/140880275
这篇关于更新到androidx.appcompat:appcompat:1.1.0后的语言更改问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!