Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set direction of whole application to RTL?

Tags:

android

I'm using API 17 and I'm looking for a way to set the whole app to rtl instead of using <android:layoutDirection="rtl"> in every single activity layout.

like image 559
mdehghani Avatar asked Jan 20 '16 20:01

mdehghani


3 Answers

I had the same problem , all you need to do is just consider all your used parent container (LinearLayout , RelativeLayout , GridView , etc) and set the LayoutDirection to RTL you can approach this way programmtically thanks to ViewCompat class to include api lower than 17.

ViewCompat.setLayoutDirection(yourParentContainer,ViewCompat.LAYOUT_DIRECTION_RTL);

note that there is no need to set the Direction for childviews separately

like image 56
Shahin Ghasemi Avatar answered Oct 16 '22 11:10

Shahin Ghasemi


Please check this text extract from android developers weblog:

To take advantage of RTL layout mirroring, simply make the following changes to your app:

1- Declare in your app manifest that your app supports RTL mirroring. Specifically, add android:supportsRtl="true" to the element in your manifest file.

2- 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”. For example, android:paddingLeft should become android:paddingStart.

If you want your app to work with versions earlier than Android 4.2 (the app's targetSdkVersion or minSdkVersion is 16 or less), then you should add “start” and end” in addition to “left” and “right”. For example, you’d use both android:paddingLeft and android:paddingStart.

the full text can be found here:

http://android-developers.blogspot.ca/2013/03/native-rtl-support-in-android-42.html

like image 27
Pooya Avatar answered Oct 16 '22 09:10

Pooya


The easiest and best way
go to the app/res/values/styles and add below code to <style> tag, that you defined its name in android manifest for example :

<style name"YourMainThemeName" parent="Parent Theme Of Your Choice">
    <item name="android:layoutDirection">rtl</item>
</style>

and now go to the app/manifests/AndroidManifest.xml and add below line code to <application> tag :

<application
        android:supportsRtl="true"
        android:theme="@style/YourMainThemeName">
</application>

now your layout directions is rtl.

like image 2
Ramin eghbalian Avatar answered Oct 16 '22 09:10

Ramin eghbalian