Explicitly set the layout direction on Android 12+
package com.fsck.k9.ui.base
import android.content.Context
+import android.os.Build
import android.os.Bundle
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
@@ -35,9 +36,18 @@ abstract class K9Activity(private val themeType: ThemeType) : AppCompatActivity(
initializePushController()
super.onCreate(savedInstanceState)
+ setLayoutDirection()
listenForAppLanguageChanges()
}
+ // On Android 12+ the layout direction doesn't seem to be updated when recreating the activity. This is a problem
+ // when switching from an LTR to an RTL language (or the other way around) using the language picker in the app.
+ private fun setLayoutDirection() {
+ if (Build.VERSION.SDK_INT >= 31) {
+ window.decorView.layoutDirection = resources.configuration.layoutDirection
+ }
+ }
+
private fun listenForAppLanguageChanges() {
appLanguageManager.overrideLocale.asLiveData().observe(this) { overrideLocale ->
if (overrideLocale != overrideLocaleOnLaunch) {
