1

It works on other android versions but below code doesn't work on android 12 devices. I use "ar" to language parameter.

val configuration: Configuration = resources.configuration
configuration.setLayoutDirection(Locale(language))
resources.updateConfiguration(configuration, resources.displayMetrics)

2 Answers2

0

I had the same problem. Maybe a cache to recreate life cycle configuration, I use this:

val intent = activity.intent
activity.finish()
startActivity(intent)

It can take effect.

Garg
  • 2,731
  • 2
  • 36
  • 47
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32750578) – Kumar Saurabh Sep 23 '22 at 12:09
0

I had the same problem and the add this piece of code and now it works. I don't know if it's the efficient way or not.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        (context as Activity).window.decorView.layoutDirection = 
            if (Locale.getDefault().language.equals("fa"))
                  View.LAYOUT_DIRECTION_RTL else View.LAYOUT_DIRECTION_LTR
}