If I set darkmode with AppCompatDelegate.setDefaultNightMode
and the system is not dark, then Configuration.setLocale
doesn't work.
I change the locale, for example, from En
to It
, all the strings are still displayed in the system language.
There are no problems if I set the same NightMode of the system (Android 10). The same problem with android 9 or less: if I set darkmode in my app and I change the context language, the activity displays text based on the language of the system.
This class represents a delegate which you can use to extend AppCompat's support to any Activity . When using an AppCompatDelegate, you should call the following methods instead of the Activity method of the same name: The following methods should be called from the Activity method of the same name:
The following is a screenshot showing the warning/error when you run the dnf or yum command as shown. To set system locale, use the localectl command. For example, if you want English – UNITED STATES OF AMERICA (US) using the UTF-8 encoding, run the following command. Next, check if the system locale has been set by running the following command.
For example, UNITED STATES OF AMERICA (US) English using the UTF-8 encoding is en_US.UTF-8 ). The following is a screenshot showing the warning/error when you run the dnf or yum command as shown. To set system locale, use the localectl command.
Note that this article should also work on any operating systems based on RHEL 8. A locale is a set of basic system parameters that define things such as a user’s language, region and any special variant preferences that the user wants to see in their user interface.
Kotlin solution
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
overrideConfiguration?.let {
val uiMode = it.uiMode
it.setTo(baseContext.resources.configuration)
it.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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With