Android below 4.2 how to set layoutDirection to be RTL
Asked Answered
R

3

14

trying to set the layout elements to be RTL ordered

in 4.2 and above the line: layoutDirection="rtl" and in the manifest: android:supportsRtl="true" is working just fine.

but for below 4.2 its not.

solution anyone ?

Ratal answered 4/12, 2013 at 13:55 Comment(2)
Can you found a solution?Lilli
check this answer, pleaseGesticulate
V
6

You won't be able to. It was added to in API Level 17 which is 4.2 so the older versions do not support it.

Vibraculum answered 4/12, 2013 at 14:3 Comment(2)
so r u suggesting me to change the order of the elements in the xml ?Ratal
Probably the best way you create a layout file for specific android API levels. e.g. layout-v17 so that the new APIs use the RTL layout, then create a layout for older verions that have the XML in the way round you needVibraculum
M
24

Just use ViewCompat using android.support.v4.view to do it.

ViewCompat.setLayoutDirection(findViewById(R.id.my_view), ViewCompat.LAYOUT_DIRECTION_RTL);
Madi answered 23/7, 2016 at 3:23 Comment(2)
Magic!! Great solution!Nurse
@ArefBahreini This method work on api 17 and above. Check inside of this method - if (VERSION.SDK_INT >= 17) { view.setLayoutDirection(layoutDirection); }Acrolein
V
6

You won't be able to. It was added to in API Level 17 which is 4.2 so the older versions do not support it.

Vibraculum answered 4/12, 2013 at 14:3 Comment(2)
so r u suggesting me to change the order of the elements in the xml ?Ratal
Probably the best way you create a layout file for specific android API levels. e.g. layout-v17 so that the new APIs use the RTL layout, then create a layout for older verions that have the XML in the way round you needVibraculum
T
2

you can change your application language and solve this problem :

String languageToLoad  = "en";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Toddy answered 1/3, 2017 at 17:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.