第一种方法:
private boolean isRtl() {
return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
}
第二种方法:
/**
* Check to see if the current layout is Right-to-Left. This check is only
* supported for API 17+. For earlier versions, this method will just return
* false.
*
* NOTE: This is based on the private API method in {@link View} class.
*
* @return boolean Boolean indicating whether the currently locale is RTL.
*/
@SuppressLint("NewApi")
public boolean isLayoutRtl(View view) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
return View.LAYOUT_DIRECTION_RTL == view.getLayoutDirection();
} else {
return false;
}
}