Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Language change issue after updating to androidx.appcompat:appcompat:1.1.0

Tags:

The link of the latest app-compat which is 1.1.0.

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).

For API 24 and above, I have used the ContextWrapper and set the locale hence works.

My question is if the androidx.appcompat:appcompat:1.1.0is the stable version why does it work for me in alpha and beta versions unlike the others here & the questions which I have tried.

  • 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)

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)?

like image 263
sanjeev Avatar asked Sep 12 '19 06:09

sanjeev


People also ask

What is Androidx Appcompat Appcompat?

appcompat:appcompat. Official Description: The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 14 or later.

What does Appcompat mean?

When new versions of android are published, Google will have to support the older versions of android. So AppCompat is a set of support libraries which can be used to make the apps developed with newer versions work with older versions.


2 Answers

Edit:

To continue using version 1.1.0 add this below your attachBaseContext:

Kotlin solution:

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

Java solution:

@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.

Old Answer:

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' .... } 

Meanwhile, I have filed an issue with Google https://issuetracker.google.com/issues/140880275

like image 117
sanjeev Avatar answered Sep 18 '22 15:09

sanjeev


There is an issue in new app compat libraries related to night mode that is causing to override the configuration on android 21 to 25. This can be fixed by applying your configuration when this public function is called:

public void applyOverrideConfiguration(Configuration overrideConfiguration

For me, this little trick has worked by copying the settings from the overridden configuration to my configuration but you can do whatever you want. It is better to reapply your language logic to the new configuration to minimize errors

@Override public void applyOverrideConfiguration(Configuration overrideConfiguration) { if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT <= 25) {         //Use you logic to update overrideConfiguration locale         Locale locale = getLocale();//your own implementation here         overrideConfiguration.setLocale(locale); } super.applyOverrideConfiguration(overrideConfiguration); } 
like image 41
Jack Lebbos Avatar answered Sep 22 '22 15:09

Jack Lebbos