Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...