fix: language revert to system default after switching back from a custom language (#3060)

This commit is contained in:
Ambarish Manna 2026-01-13 00:44:19 +05:30 committed by GitHub
parent e4ef866b56
commit 8b3f4f915c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,8 +10,8 @@
package cmp.android.app
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
@ -33,9 +33,9 @@ import kotlin.getValue
* This class is used to set the content view of the activity.
*
* @constructor Create empty Main activity
* @see ComponentActivity
* @see AppCompatActivity
*/
class MainActivity : ComponentActivity() {
class MainActivity : AppCompatActivity() {
/**
* Called when the activity is starting.
* This is where most initialization should go: calling [setContentView(int)] to inflate the activity's UI,
@ -70,9 +70,15 @@ class MainActivity : ComponentActivity() {
AppCompatDelegate.setDefaultNightMode(it)
},
handleAppLocale = {
it?.let {
if (it.isNullOrBlank()) {
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(it),
LocaleListCompat.getEmptyLocaleList(),
)
} else {
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(
it,
),
)
Locale.setDefault(Locale(it))
}