I have an application on which I do not have the liberty to add supportsRtl = true
With that being set to false I have two questions.
1) Is it possible to set supportsRtl true programatically?
2) This is the code that doesn't work when supportsRtl = false
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
Any ideas as to how can I have a single layout file be displayed in ltr/rtl while the supportsRtl is false?
Setting only one layout direction to RTL wouldn't be a good idea since users who uses RTL direction will need to see the right texts direction for all Activities-layouts.
Just set the android:supportsRtl="true" in the AndroidManifest.xml then go to:
Refactor -> Add RTL Support Where Possible
This will satisfy your need by adding RTL to where it's possible.
About that start-end attributes in the xml side, all you need to do is:
Right-click on the project -> Replace in Path
Then replacing your start-end attributes easily by using this.
Related
I want to set rtl = true in Manifest for all layers , except one of the layers .
how can do it ?
You can set the android:layoutDirection property in XML, it can have either rtl or ltr values.
The property overrides android:supportsRtl property in "application" segment of your manifest file.
I think for all layers you need to define rtl = true and for one layer make it false. That should work.
I am developing an app which supports two languages: English("en") and Persian("fa"). I have set android:supportsRtl="false" in AndroidManifest.xml since I need everything to be from left to right. I set margins for all views that I have but for the ones containing a string, it is not working right and it still seems like it is setting the directions from right to left. How can I fix that? I also tried changing the layoutDirection manually to left to right but that did not work either.
You must handle your locale in all activities. Android by default uses the locale of the device to select the appropriate language dependent resources.
Also you must consider project minimum sdk. I recommended to you change it to 16 or higher: minSdkVersion 16
Maybe this link help you.
I set margins for all views that I have but for the ones containing a string, it is not working right
For this for example you must use from android:layout_marginEnd instead of android:layout_marginRight. Also in default create your layout for en locale and then handle and change it by app locale to fa or another locale.
You have to use instead of the right from the end and instead of the left from the start
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تست"
android:gravity="start"/>
I've been trying to make a ListView to work as RTL (Right to Left).
I've added the following line in the ListView and LinearLayout properties:
android:layoutDirection="rtl"
and it still shows the list from left to right.
Any ideas?
Thank you all but I solved it with:
android:textDirection="rtl"
I've added it to the ListView and the layouts, and it worked. Next time you should try considering using this too for RTL layouts.
To take advantage of RTL layout mirroring, simply make the following changes to your app:
Declare in your app manifest that your app supports RTL mirroring.
Specifically, add android:supportsRtl="true" to the <application> element in your manifest file.
Change all of your app's left/right layout properties to new start/end equivalents.
If you are targeting your app to Android 4.2 (the app's
targetSdkVersion or minSdkVersion is 17 or higher), then you should
use start and end instead of left and right. For example,
android:paddingLeft should become android:paddingStart.
If you want your app to work with versions earlier than Android 4.2
(the app's targetSdkVersion or minSdkVersion is 16 or less), then you
should add start and end in addition to left and right. For
example, you’d use both android:paddingLeft and android:paddingStart.
RTL layout support feature is supported on Android 4.2(API level 17) or above only . Please Add android:layout_gravity="left/right" in your parent Layout . And also allow android:textAlignment.
Set minSdkVersion=17
Please read http://developer.android.com/reference/android/view/View.html#attr_android:layoutDirection
This will automatically adjust according to the device locale
android:textDirection="locale"
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.
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".
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="ltr">
for letf to right all layout content.
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(...)
If you want to force your application to ltr even on rtl languages you don't need layout direction (it works on api>17) you can just set android:supportsRtl to false.
I am working on an application, using API 17 (4.2). In the application I am designing a layout class, and I would like to configure it according to the layout direction. However, I haven't been successful in retrieving the applied layout direction within the class:
LinearLayout layout = newLayout(context);
layout.setLayoutDirection(LAYOUT_DIRECTION_RTL);
int ld = layout.getLayoutDirection(); // STILL 0! I was expecting 1
My question is, how do I configure a layouts direction, and retrieve it within the class?
add this to your AndroidManifest.xml:
<application
...
android:supportsRtl="true"
>
As View checks RTL support first, if true, then resolve layout direction.
You can get more details in View.resolveLayoutDirection().