in AndroidManifest.xml, but I need one of the vie...">

Override supports Rtl in one of the layouts

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

In particular, I want to make the linear layout go from left to right, and not by default from right to left, even if the language is from right to left.

+6
source share
4 answers

Normally gravity="left" enough for the text to be left to right. But this did not help in the direction of the linear layout. The solution was to add android:layoutDirection="ltr" .

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

for letf to fix the entire contents of the layout.

+1
source

To complete responses other than XML, the layout direction can also be programmatically changed using ViewCompat.setLayoutDirection(view, LayoutDirection.RTL) . This API can be used from API 19 onwards, so if your minimum version of the SDK supports APIs below 19, you must run if -check:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { ViewCompat.setLayoutDirection(...) 
+1
source

If you want your application to use ltr even in rtl languages, you do not need the direction of the layout (it works with api> 17), you can just set android:supportsRtl to false.

0
source

All Articles