Changing the orientation of the navigation bar (RTL)

My application supports 4 different languages, two of them are written from right to left.

If I change the language on the Android system and then run the application, everything will be fine. I get a mirror layout (RTL), and even the navigation bar is mirrored.

My problem is that I have a button in the application for changing the language. To programmatically change the locale, I do this:

Locale locale = new Locale("ar")
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

And then recreate the action:

this.recreate();

Activity is recreated from RTL, but the navigation bar retains the old style (not mirror):

navigation bar

Can I display the navigation bar programmatically?

EDIT (ADD IMAGES):

If I change the system language, everything works fine:

right

If I programmatically change the language, the navigation bar does not change:

wrong

+2
source
1

Android 4.2.2 (API- 17) RTL .

, , RTL . RTL. , , RTL, , .

RTL, (RTL), . AndroidManifest.xml android:supportsRtl="true"

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
...
</application>

<application>, onCreate() forceRTLIfSupported(); .

@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);


    }
}

:

enter image description here

:

, "start" "right", :

  • - RTL (, ...)
  • Android- API 17

: Android Dev

enter image description here

enter image description here

+1

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


All Articles