Identifying RTL language in Android

前端 未结 16 1747
既然无缘
既然无缘 2020-11-28 06:59

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

16条回答
  •  没有蜡笔的小新
    2020-11-28 07:25

    You can detect if a string is RTL/LTR with Bidi. Example:

    import java.text.Bidi;
    
    Bidi bidi = new Bidi( title, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT );
    
    if( bidi.isLeftToRight() ) {
       // it's LTR
    } else {
       // it's RTL
    }
    

提交回复
热议问题