How to make dialog and the top menu remain the same orientation across different languages?

34 views Asked by At

I'm trying to keep my app orientation the same orientation as an English user, even though my phone is with Hebrew settings. For the Activities, I'm using the android:layoutDirection="ltr" command, but this command does not work for the alert dialogs (the positive and negative buttons are on the left side of the dialog and on the wrong order) and the top menu. is there a way to force the app keep the orientation?

1

There are 1 answers

1
snachmsm On

try this for dialogs (they appear in new Window and params set to Activitys window aren't applied, both xml and by code)

Dialog dialog = dialogBuilder.create();
ViewCompat.setLayoutDirection(dialog.getWindow().getDecorView(), LayoutDirection.LTR);
dialog.show();

before creating dialog (build() call) its window isn't created (yet), even layout isn't parsed/drawn, thus now you are getting exception referencing to not-yet-existing view

(showing includes creating step, so you can also try to call setLayoutDirection just after show() call)