Make Android layouts independent of system locale? - android

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).

Related

How to manage RTL languages phones in English application

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.

Is there a way to change the layout direction for my app in android

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

How to make my application independent phone language

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.

android layout compatibility, programmatically vs resource file, specifically for language orientation

My application needs to support languages that are read from right to left and vice verca.
Right now it supports only right to left, and all I need to do is change a bunch of layouts.
The approach I want to take is to have layouts in two different folders (i.e layout and layout-de), because doing it programatically, for every layout, is a nightmare.
However, Google state here http://developer.android.com/guide/topics/resources/localization.html#strategies
"you can create an alternative layout for that language (for example res/layout-de/main.xml). However, doing this can make your application harder to maintain"
My question is, which way is better, programmatically or separate layout folders
I want to stress, since this topic has been discussed in other threads:
I am NOT talking about strings. ONLY layouts
My only concern is the language orientation(left to right and right to left), when it comes to the layout.
Thank you very much in advance
Since Android 4.2 there is native RTL support. Most attributes that used "left" or "right" in their names now have equivalents that use "start" and "end" (e.g. android:paddingStart="..." or android:gravity="end").
Read about it here: http://android-developers.blogspot.com/2013/03/native-rtl-support-in-android-42.html

What is the difference between Android margin start/end and right/left?

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.

Categories

Resources