How to switch language from English to Arabic so that it can be read right to left?

2.6k views Asked by At

While Switching language from English to Arabic, the layout is changing from left to right. How do I change the textView from left to right. Example (English) Ramesh driving with a speed of 34kmph. (Arabic) hpmk43 fo deeps a htiw gnivird hsemaR

Edit 1: Please find the below image is it correct?

Arabic version English Version

3

There are 3 answers

0
Arjun On

Change all of your app's left/right layout properties to new start/end equivalents.

Simply example, use in android:gravity.

Don't forget to declare in your app Manifest that your app supports RTL mirroring: add android:supportsRtl="true" to the element in your Manifest file.

0
Rajesh On

setLocale("en");//set English

setLocale("ar");//set Arabic

public void setLocale(String lang) {
        Locale locale = new Locale(lang);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());
    }

will automatic RTL after set locale as English and LTR set locale as Arabic. //Don't forget to restart your app. after set locale

No need to change gravity

0
Sachin Chauhan On

To make your TextView work for RTL, you should add layout properties of RTL.

Use android:layout_marginStart in place of android:layout_marginLeft and android:layout_marginEnd in place of android:layout_marginRight

For left-to-right flow, start=left, end=right.

For right-to-left flow, start=right, end=left.

This RTL support was added in API Level 17, as part of Android 4.2's support for RTL layouts. This will help you https://developer.android.com/about/versions/android-4.2.html#RTL