I am programming an Android application. This application isn't translated to any right to left language (like Arabic or Hebrew). I've noticed that right to left language people has it in English, but with right to left layout. The drawer menu is on the right instead of the left and the text is right aligned.
What is the good practice to manage this? Should I let the RTL layout because they are used to it or should I force LTR layout because the app is in English?
If you’re not supporting RTL languages you should not support RTL layouts (LTR languages looks pretty bad in RTL languages).
Just add android:supportRtl="false" attribute in your manifest's application tag.
It should solve it.
Even though false is the default value, one of your dependencies can override it to true if you don't set it explicitly.
Confirm that this is the issue by checking the final merged manifest if android:supportRtl is true.
Related
I have developed an app in English language. When i change my android language to a right-to-left (later rtl) language , my app goes rtl layout but I don't want that. I want my app layout to stay left-to-right (later ltr) whether android language is ltr or rtl.
I know there is layoutdirection in a activity attributes but it's not for APIs below 17.
I'd still say to use this:
Add in styles.xml in your Base App theme style:
<item name="android:layoutDirection">ltr</item>
17+ is legitimate.
Just do this in manifest
android:supportsRtl="false"
with support rtl your layout in english is still ltr.
rtl is on only for languages how japanese and so on.
the most devices are already API 17+.
On emulator or device you can change main language, so you can use rtl or rtl layout depend on selected language.
Try to put all of your resources (layouts, strings, drawable ... etc) in rtl language folder like
layout-ar and remove default layout folder
also use values-ar, drawable-ar .... etc only
i think this will force android to read from it.
Is there any way to force left to right layouts when the device language is any rtl language?
All XML Screens got broken when the language is changed to Arabic?
You can forcefully disable rtl by changing its property supportRtl="false" in your AndroidManifest.xml file.
I'd like to have different layout design based on location. actually I know we can have different layout based on mobile device size.
As you know Android has very good feature that you can inflate all texts in your application based on location which is called Localization.
I am looking for a kind of similar feature that force my android app to inflate suitable layout design based on location.
In Persian and Arabic, the orientation of components is better to be Right-To-Left, although it is possible by designing exact wanted layout, but i don't know how to make it international because regardless of size, I need to have different layout design orientation based on user location, like USA, Germany, Iran and etc.
Is there any easy and automatic way to change layout orientation from left-to-right to right-to-left based on user location? I've checked similar question in stackoverflow, but that solution is not my aim and goal.
thank you :-)
You can use layout subfolders to provide different layouts depending on language direction. (layout-ldrtl).
Also You can provide different layouts depending on language (layout-ar in Your case).
In that case layouts that contained in simple layout folder will be defaults.
More info You can find in developer site
ofcurse, it has some ways to make it works.
RTL Layouts directory(the the right way)
The layout direction of your application. ldrtl means
"layout-direction-right-to-left". ldltr means
"layout-direction-left-to-right" and is the default implicit value.
This can apply to any resource such as layouts, drawables, or values.
For example, if you want to provide some specific layout for the
Arabic language and some generic layout for any other "right-to-left"
language (like Persian or Hebrew) then you would have:
res/
layout/
main.xml (Default layout)
layout-ar/
main.xml (Specific layout for Arabic)
layout-ldrtl/
main.xml (Any "right-to-left" language, except
for Arabic, because the "ar" language qualifier
has a higher precedence.) Note: To enable right-to-left layout features for your app, you must set supportsRtl
to "true" and set targetSdkVersion to 17 or higher.
https://developer.android.com/guide/topics/resources/providing-resources.html
Run time
https://stackoverflow.com/a/23203698
Set LAYOUT_DIRECTION="rtl"
and set GRAVITY="start"
What is difference between Android margin start and right (or margin end and left)?
It is trivial question, but I cannot seem to learn from the documention what is difference between view start/end and left/right. It could be that I just don't understand something, but I cannot make any progress with this at all.
For left-to-right flow, start=left, end=right.
For right-to-left flow, start=right, end=left.
The "start" and "end" concepts were added in API Level 17, as part of Android 4.2's support for RTL layouts.
Android supports RTL layouts from API 17+ i.e., Android 4.2 (Jelly Bean).and when we make our layout to support both RTL and LTR then we can not use layout_marginleft and layout_marginRight there we use layout_marginstart and layout_maginend .
If you are familiar with languages like Arabic or Urdu you will be aware that they start from right to left unlike English where we read from Left to Right.
So if we set margins using Margin right/left then we don't care about the language but we just directly add the margin according to the universal left and right.
But if we use Margin start/end then we care about the language. So let's say if the app has a UI which is written in Arabic language then the start will be the right side and if the UI is in English the start will be on the left side.
Now when to use right/left and when to use start/end :
So if you are sure that your app is going to have no language needs and you need to show your UI from left to right always like in English language then you can opt for left/right margin as it's easy and simple to understand.
But if you are building a multi lingual app then you can opt for start/end margins as you don't have to create multiple UI's.
I read this sentence " Android 2.3 added support for right-to-left (RTL) languages"
and now I want to add RTL support to my app. But I do not know what is qualifiers to add to my layouts.
About res/values/strings.xml , I can named like this res/values-ar/strings.xml
I want to have different layout for RLT languages. I do not want to have just different strings , I also want different layout. What the layout folder name should look like ?
At this moment for the left to right languages it is named
res/lauyots/main.xml
but I do not know how to name it for RTL languages
Is this kind qualifier is present at all ?
You can find -ldrtl and -ldltr qualifiers in Providing resources
res/layout-ldltr/ (Left to Right, default value)
res/layout-ldrtl/ (Right to Left)
#Silwek is right. This is his answer, I am merely putting it here because my answer has been marked as answered.
res/layout-ldltr/ (Left to Right, default value)
res/layout-ldrtl/ (Right to Left)
Old Answer
Check Localization and Multiple Screen Support, they give you idea about resource folders and qualifiers.
You can use locale specific resources and layout like this:
For language specific resources:
res/values/strings.xml
res/values-fr/strings.xml (French)
res/values-ja/strings.xml (Japanese)
For language specific layouts:
res/layout-fr/main.xml
res/layout-ar/main.xml
Using rtl with resources is not a correct approach .. you missed that Devices with RTL locale such Arabic,Hebrew, Persian ... usually enforce all apps ( even with english language only ) to use rtl as language direction and text direction... and here where its dangerous to use rtl in resources because you will cause using your RTL layout for all languages for RTL Locale device. Better to track languages.