Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override RTL support on a layout in Android

I set android:supportsRtl="true" in the <application> tag in AndroidManifest.xml, but I need to force one of the views to be left-to-right nonetheless, even when the language of the interface is Hebrew or Arabic. How can I force a specific view to be LTR in an RTL application?

Specifically, I want to force some linear layout to go left-to-right instead of the default right-to-left even when the language is right-to-left.

like image 442
Ilya Kogan Avatar asked Apr 06 '15 05:04

Ilya Kogan


3 Answers

Generally gravity="left" is enough to force text to be left-to-right. But it didn't help with the direction of a linear layout. The solution was to add android:layoutDirection="ltr".

like image 81
Ilya Kogan Avatar answered Oct 16 '22 06:10

Ilya Kogan


To complete the answers, aside from XML, layout direction can also be changed programmatically with ViewCompat.setLayoutDirection(view, LayoutDirection.RTL). This API can be used from API 19 and onwards, so If your min sdk version supports API below 19, an if-check needs to be performed:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            ViewCompat.setLayoutDirection(...)
like image 39
Adib Faramarzi Avatar answered Oct 16 '22 06:10

Adib Faramarzi


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layoutDirection="ltr">

for letf to right all layout content.

like image 45
Samet ÖZTOPRAK Avatar answered Oct 16 '22 06:10

Samet ÖZTOPRAK