How can I change entire app layout direction to RTL? I am writing an app that user must select it's language in first launch and the layout should change based on user selection to RTL or remains LTR. I used to add android:supportsRtl="true"
to the AndroidManifest
and android:layoutDirection="rtl"
for each layout but this approach have some problems like below :
One problem is when I change the direction to RTL the ActionBar
home icon or navigation button (when home as up is enabled) remains LRT and just move to the right.
I also tried to change direction programmatically and the result was the same :
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){ getWindows().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); }
Is there any way to force all activities to become RTL at once or we should set direction in each activity separately?
Just go to Android Studio > Refactor > Add RTL support where possible… I would recommend you checking your app once after applying this change as you might not want all your Layouts/Views to be RTL. If you want to force any layout to LTR then just add android:layoutDirection="ltr" to that view.
Once you've accessed the menu, scroll down to find the “Force RTL layout direction” tab. Tap on it to activate the option, and you're done. All system menus and Google apps will reflect the change: phonebook, messaging, Google Play, Gmail, notifications area, and so on.
In your android phone, tap on “Settings” icon. Now tap on developer options and search for “Force RTL layout direction”. Tap on it to enable RTL feature.
You can use this piece of code while your application's minSdk >= 17.
I used fa
for Farsi
, you can use other rtl language.
Configuration configuration = getResources().getConfiguration(); configuration.setLayoutDirection(new Locale("fa")); getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With