Hi! When I change the app language, the screen so...
# android
n
Hi! When I change the app language, the screen somehow blacks out or flashes. How can I fix this? I’ve tried numerous solutions, but none of them worked. Only the language screen is built with Compose; the others use XML
Copy code
private fun applyAppLocale(languageCode: String) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        // Android 13+: Use LocaleManager for per-app persistence
        val localeManager = context.getSystemService(LocaleManager::class.java)
        localeManager.applicationLocales = LocaleList.forLanguageTags(languageCode)
    } else {
        // Pre-Android 13: Use AppCompatDelegate
        val locales = LocaleListCompat.forLanguageTags(languageCode)
        AppCompatDelegate.setApplicationLocales(locales)
    }

    // Immediate update for resources (affects View-based UI)
    val config = Configuration(context.resources.configuration)
    config.setLocale(Locale(languageCode))
    @Suppress("DEPRECATION")
    context.resources.updateConfiguration(config, context.resources.displayMetrics)
}
not kotlin but kotlin colored 5
c
Image from iOS.jpg
j
That'd be a configuration change restarting your Activity. If you're using Compose properly you can safely turn off recreation, since states will automagically update 🤔