Identifying RTL language in Android

前端 未结 16 1757
既然无缘
既然无缘 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:18

    For more precise control over your app UI in both LTR and RTL mode, Android 4.2 includes the following new APIs to help manage View components:

    android:layoutDirection — attribute for setting the direction of a component's layout.
    android:textDirection — attribute for setting the direction of a component's text.
    android:textAlignment — attribute for setting the alignment of a component's text.
    getLayoutDirectionFromLocale() — method for getting the Locale-specified direction
    

    Thus getLayoutDirectionFromLocale() should help you out. Refer the sample code here : https://android.googlesource.com/platform/frameworks/base.git/+/3fb824bae3322252a68c1cf8537280a5d2bd356d/core/tests/coretests/src/android/util/LocaleUtilTest.java

提交回复
热议问题