Is there a way to identify RTL (right-to-left) language, apart from testing language code against all RTL languages?
Since API 17+ allows several resources for RTL a
Get it from Configuration.getLayoutDirection():
Configuration config = getResources().getConfiguration();
if(config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
//in Right To Left layout
}
Because English language devices are supporting RTL, you can use this code in your MainActivity to change device language to english and you don't need to "supportRTL" code.
String languageToLoad = "en"; // your language
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
You can use TextUtilsCompat from the support library.
TextUtilsCompat.getLayoutDirectionFromLocale(locale)
You can check like this if you want to check for API lower than 17
boolean isRightToLeft = TextUtilsCompat.getLayoutDirectionFromLocale(Locale
.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
OR for API 17 or above
boolean isRightToLeft = TextUtils.getLayoutDirectionFromLocale(Locale
.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;