Identifying RTL language in Android

cyanide picture cyanide · Sep 25, 2013 · Viewed 42.2k times · Source

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 and LTR, I assume, there should be a way, at least from API 17.

Answer

Morrison Chang picture Morrison Chang · Sep 25, 2013

Get it from Configuration.getLayoutDirection():

Configuration config = getResources().getConfiguration();
if(config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
    //in Right To Left layout
}