Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Application force RTL

I need to force my application to run RTL regardless the phone language it can be done by Developer mode and i need it be added programatically to the application to force the application display to rtl

android:supportsRtl="true"

this working depend on phone languages Thanks

like image 484
mhany Avatar asked May 14 '15 15:05

mhany


People also ask

How do I force RTL on android?

To force right-to-left layouts on your Android device you need to open Settings, and access the Developer options menu (if developer options aren't enabled, here's how to do it). 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.

How do I disable RTL on android?

Change all of your 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 or minSdkVersion is 17 or higher), then you should use “start” and “end” instead of “left” and “right”.

What is RTL in android?

A layout direction can be left-to-right (LTR) or right-to-left (RTL). It can also be inherited (from a parent) or deduced from the default language script of a locale.


1 Answers

Set the language of your app on startup like :

        Resources res = getResources();
        Configuration newConfig = new Configuration( res.getConfiguration() );
        Locale locale = new Locale( appLanguage );
        newConfig.locale = locale;
        newConfig.setLayoutDirection( locale );
        res.updateConfiguration( newConfig, null );

setLayoutDirection is important in case your appLanguage is differ from the Phone language.

like image 80
Gugelhupf Avatar answered Sep 21 '22 16:09

Gugelhupf