I use Android Studio's Navigation Drawer Activity in My Application but when I change Language of System to Right to Left Language My Application's UI vary
Left to right(My main UI)
Right to left
I want to stay the same upon language change
What can I do?
If your API is 17+ you can use the:android:supportsRtl="true"
in the manifest
If you want your views to remain same set android:supportsRtl="false" for API level 17+. And make sure you are not using start and end as gravity values to any view.Because start and end are used for applications supporting RTL.Instead use left and right.
If you want your views to change according to language then set android:supportsRtl="true" and set gravity values as start and end instead of left and right.
Note: start and end only works with device supporting API level 17+.
For more reference see This blog.
Just set android:supportsRtl="#string/is_rtl" for your application node in the manifest and you are good to go.
Related
I need to change the layout direction inside my app, from LTR to RTL and vise versa, I looked there is no clear solution online, is this process simple or not, I mean it must be property inside the app you can change this property easily for all the layouts in your app, any ideas?
Note: I want to change the language and the layout just inside my app.
Put your device in RTL mode, you can do this in the develop settings (Force RTL layout direction).
You should ensure that all your layouts don't use "left" and "right" properties, e.g layout_marginLeft, instead they should use layout_marginStart and layout_marginEnd.
This will mean that when run on device that's set to read right to left (e.g arabic), all the layouts will mirror correctly.
If you don't want to change the whole device into RTL, paste this in the onCreate method of every activity in your app (paste it before super and before you inflate the content view.
Java: getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
Kotlin: window.decorView.layoutDirection = View.LAYOUT_DIRECTION_RTL
(I don't believe you'll need to add this to every fragment, only activities).
You can force RTL like this
window.decorView.layoutDirection = View.LAYOUT_DIRECTION_RTL
You can also set it to LAYOUT_DIRECTION_LTR for left-to-right layout direction
I am using an android library (leanback library for android tv) and want to set my app layouts independent of the system locale.
In other words, as all of my users use right to left language and layout, I want to prevent rendering layout in "Left to Right" mode even if system language is on a LTR lang like english.
So can I set a flag or do other stuff to make the app ignore system locale totally?
EDIT : Thanks to Andres comment, I followed this link and it works perfectly.
Use android:layoutDirection="rtl" for your layout's root and android:layout_gravity="start" for child views.
This way you force your layout to be right to left and all child views appear on the right side of the parent (start means right in rtl direction).
i build new application with simple login activity with firebase when i install on phone with english language it work perfectly.
but when i change phone language to arabic it dosen't work.
all data entered was in english language.Any ideas?!!
for UI design it makes difference if your user phone is using right to left language or left to right language
if this is the case you should decide you want your app adapt changes or be fixed
for example you can use layout_marginLeft instead of using layout_marginStart
but for preferences activity you cannot change layout direction in easy way
If you want to support arabic your app should support RTL.
you need to change all your layouts where ever you are using left and right to start and end.
Also you need add textAlignment property to textviews.
I have a multi language application. which works fine for the app is in the English language and all labels are placed perfectly at the required places.
Now I have a scenario when I change the language of the from English to Arabic app is doing the translation correctly. But issue is with the placement of the labels, I want to place the labels from rtl instead of ltr.
For API level 17 or higher Set the property textDirection in your XML
android:textDirection="anyRtl"
For below API level 17 use property textAlignment in your XML
android:textAlignment="viewStart"
In order to support RTL in your app, you first need to add android:supportsRtl="true" to the <application> element in your manifest file.
If your app API ≥ 17, replace all
layout_marginLeft with layout_marginStart
layout_marginRight with layout_marginEnd
paddingLeft with paddingStart
paddingRight with paddingEnd
and if your app support API<17 add layout_marginStart, layout_marginEnd along with layout_marginLeft, layout_marginRight
In addition to #Ankita's answer you can use textDirection:"anyRtl", which will set the direction of the text to the right if it finds any strong "right direction" character or to the left he it finds a strong "left direction" character
From Documentation of views
Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. If there are neither, the paragraph direction is the view's resolved layout direction.
I would recommend making 2 different layouts for each view one with left direction and one with right direction. In that case you will have the liberty to adapt your layout to the type of text you're going to have and so use textDirection="rtl"
Either cases are good, the first one from Ankita is useful when you don't need full control of the display and you can permit yourself to trust the "anyRTL" algorythm.
The second solution, gives you more work but will give you full control over the result layout.
One last thing. I'm not sure but by creating a layout with the arabic locale I think the text direction changes automatically
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.