My app supports 3 (soon 4) languages. Since several locales are quite similar I\'d like to give the user the option to change locale in my application, for instance an Itali
For those who tried everything but not not working. Please check that if you set darkmode
with AppCompatDelegate.setDefaultNightMode
and the system is not dark, then Configuration.setLocale
will not work above Andorid 7.0.
Add this code in your every activity to solve this issue:
override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
if (overrideConfiguration != null) {
val uiMode = overrideConfiguration.uiMode
overrideConfiguration.setTo(baseContext.resources.configuration)
overrideConfiguration.uiMode = uiMode
}
super.applyOverrideConfiguration(overrideConfiguration)
}