I have Android application for which I need to force the entire app's layout to RTL
. I'm doing this by the use of the xml attribute android:layoutDirection="rtl"
.
It's all working fine until in one of my Activities I need to manually finish()
the Activity and return back to the previous Activity and henceforth every view that I have manually forced the RTL
direction on, reverts back to the LTR
mode until I fully close the app and start it again.
I am using this piece of code in my BaseActivity
to also force the language which is working fine thus far.
override fun onResume() {
applyLang()
super.onResume()
}
private fun applyLang() {
val dm = resources.displayMetrics
val conf = resources.configuration
val locale = Locale(FA_LANG.toLowerCase())
Locale.setDefault(locale)
conf.setLocale(locale)
resources.updateConfiguration(conf, dm)
}
Notes:
I have tried putting the following code in the onCreate
of my BaseActivity
to no avail:
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);