Set locale using the back button

I am working on setting the language in my application. I was able to change the locale from my main activity using

Resources resources = getResources();
Configuration configuration = resources.getConfiguration();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
configuration.setLocale(new Locale("ar"));
resources.updateConfiguration(configuration,displayMetrics);
recreate();

Everything worked fine, but I noticed that the back button did not change direction to RTL:

enter image description here

This is my expected behavior when I install the language in RTL:

enter image description here

Is it possible?

+4
source share
3 answers

Try calling this method when installing Arabic:

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void forceRTLIfSupported()
{
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){

      //HERE CHECK CONDITION FOR YOUR LANGUAGE if it is AR then
      //change if it is english then don't

      getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);


    }
}
+1
source

, Locale . , Locale (rtl ltr) . Locale Context , Context / (, , ..). , .

, Locale (, , , ..), SET_CONFIGURATION. docs, SET_CONFIGURATION , . , , , , , adb shell pm grant . , , , .

0

The direction of the navigation bar (and other parts of the OS, such as Settings) is not related to the application. A user may have an LTR OS with an RTL application. therefore, changing the locale and direction of the application does not affect the underlying OS, and the user must manually change it.

0
source

Source: https://habr.com/ru/post/1694387/


All Articles