This code working fine for android 13 and later but not for below android 13
fun changeLanguage(context: Context, language: Languages) {
val languageString = when (language) {
Languages.ENGLISH -> "en"
Languages.BENGALI -> "bn"
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// Use LocaleManager for Android 13 and later
val localManager = context.getSystemService(LocaleManager::class.java)
localManager?.applicationLocales = LocaleList.forLanguageTags(languageString)
} else {
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(languageString))
}
}
enum class Languages {
ENGLISH,
BENGALI
}
Top comments (0)