Android provides a feature to make our APP bidirectional(LTR & RTL). This feature was introduced in android 4.1 (Jelly Bean) for TextView and EditText elements, allowing apps to display and edit text in both left-to-right (LTR) and right-to-left (RTL).
There was full support for RTL feature in android 4.2 version. It makes the exact mirror image of our existing layout.
Our APP will continue to appear as we have set it in default direction. But, with a few simple changes, APP will be automatically mirrored when the user switches the system language to a right-to-left script (such as Arabic, Hebrew, or Persian).
Android 4.2 includes the following APIs to help manage View components:
- android:layoutDirection — attribute for setting the direction of a component’s layout.
- android:textDirection — attribute for setting the direction of a component’s text.
- android:textAlignment — attribute for setting the alignment of a component’s text.
- getLayoutDirectionFromLocale() — method for getting the Locale-specified direction
Make these changes to support bidirectional feature by android:
- add-
android:supportsRtl="true"
to the<application>
element in manifest file. - Change all of app’s “left/right” layout properties to new “start/end” equivalents.
- If you are targeting your app to Android 4.2 (the app’s
targetSdkVersion
orminSdkVersion
is 17 or higher), then you should use “start” and “end” instead of “left” and “right”. For example,android:paddingLeft
should becomeandroid:paddingStart
- If you want your app to work with versions earlier than Android 4.2 (the app’s
targetSdkVersion
orminSdkVersion
is 16 or less), then you should add “start” and end” in addition to “left” and “right”. For example, you’d use bothandroid:paddingLeft
andandroid:paddingStart
- Or
If you are using Android studio then open your project in Android Studio and follow the steps:- Click on “Refactor” in android studio’s menu bar.
- There will be a pop with options, reach to the end of the menu and click on “Add RTL Support where possible”.
- Now, you will get a popup. Tick the checkbox accordingly.
Note: If you are not a developer and still want to see the miracle then follow the steps:
- In your android phone, tap on “Settings” icon.
- Scroll down the list. You will get “Developer options”, if not then no need to worry follow: Settings > About device > Build number
Once you’ve found the Build number section of the settings, tap on the section 7 times. Now there will be “developer options” before “about phone”
- Now tap on developer options and search for “Force RTL layout direction”.
- Tap on it to enable RTL feature.
Have fun!