1

I built an app that's completely in Arabic.. I need the app to run as if the device language is Arabic no matter what language is already set, since the app will only be used be native Arab..

this gives so many advantages in the design such as.. titles in Dialog Alert is to the right, navigation drawer is to the right..etc Actually it's weird the other way..

does forcing a locale is the solution? if yes, do I have to create new resources files, or the app will read the default ones but reformat them according to the locale?

how to do this.. thanks in advance

Omar Labib
  • 55
  • 9

2 Answers2

2

If your app only for Arabic, You can convert your activity to RTL by,

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}

If your app can be for all language, you can do as per selected locale,

Resources resources = getResources();
Locale locale = resources.getConfiguration().locale;
Configuration config = resources.getConfiguration();
config.locale = locale;
if (Build.VERSION.SDK_INT >= 17) {
    config.setLayoutDirection(locale);
}
resources.updateConfiguration(config, resources.getDisplayMetrics());

Declare android:supportsRtl=”true” in the application tag of AndroidManifest.xml

Dhruv Patel
  • 1,529
  • 1
  • 18
  • 27
1

You have to just declare android:supportRtl="true" in the AndroidManifest.xml file to support right to left layout.

Piyush
  • 2,589
  • 6
  • 38
  • 77
Kinjal
  • 327
  • 2
  • 11