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 ?

gabhor
  • 669
  • 9
  • 23
Nadav
  • 220
  • 4
  • 12

3 Answers3

24

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

ViewCompat.setLayoutDirection(findViewById(R.id.my_view), ViewCompat.LAYOUT_DIRECTION_RTL);
Aref Bahreini
  • 774
  • 8
  • 14
  • 1
    Magic!! Great solution! – idish Jul 05 '17 at 21:46
  • @ArefBahreini This method work on api 17 and above. Check inside of this method - if (VERSION.SDK_INT >= 17) { view.setLayoutDirection(layoutDirection); } – Reza Mar 19 '19 at 15:44
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.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Boardy
  • 35,417
  • 104
  • 256
  • 447
  • 1
    so r u suggesting me to change the order of the elements in the xml ? – Nadav Dec 04 '13 at 14:04
  • 1
    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 need – Boardy Dec 04 '13 at 14:57
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());
arya hm
  • 19
  • 3