I know that android:supportsRtl="true" method fits the app to the screen in different sizes. But if a phone has a language which is right-to-left instead of left-to-right, like Persian the buttons or text views, specially if they are in rows, will be right-to-left.
How can I prevent app's layout's changing based on language?
Or keep it in English language in all phones?
Thanks for helping.
In your manifest.xml, inside the application tag add this line.
<application
...
android:supportsRtl="false"
...
Set all the strings in your resources with translatable=false in your strings definitions (as shown here) and set supportsRtl=false, so that your app will never attempt to adapt to the phone conditions.
For language, another strategy could be simply to not provide any translation for the resources: this way the system cannot use layout resources relative to your phone language and region, simply because there aren't any.
Try adding android:layoutDirection="ltr" to your layouts and appBar. It can solve your problem.
Adding android:supportsRtl="false" to manifest can help you, But it isn't enough.
Related
When operating on a LTR language phone my app looks fine like this:
but when operating on a RTL language phone my app gets either glued to the right like this:
or you can't even see the screen like this:
how can i make my app look exactly as it looks on a LTR phone?
p.s i have already tried the refactor adjust to RTL language and it didnt change anything.
thanks
It sounds like you want to essentially disable RTL support in your app. To do this, go to your AndroidManifest.xml and add this attribute to the <application> tag:
<application
android:supportsRtl="false"
...>
Note that this attribute exists by default, but is set to true (so you just need to change the value to false).
In your Xml while specifying margins for your views always use the attribute marginStart and marginEnd instead of marginLeft and marginRight.For more info on this refer this answer here.
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"
I'm using font-awesome for some of my buttons. One of them is a "back" button. On LTR languages, I want the button to be an arrow that points to the left, and on RTL, an arrow that points to the right.
Right now what I'm doing is this:
I'm holding two strings in my "values" folder
<string name="icon_back_ltr"></string>
<string name="icon_back_rtl"></string>
<color name="icon_back_color">#FFFFFF</color>
Then, I check programatically if the device language is an RTL language. If so, I modify the text on the button accordingly.
My question is, is there a better way to do it? One that does not require checking for layout direction programatically? For example, I know I can define the word "Hello" to be in English (using "values") and then to be something else in Hebrew (using "values-iw). The question is, can I define a certain string to be text A in all LTR languages and then to be text B in all RTL languages?
Define two reource driectories values-ldrtl (means "layout-direction-right-to-left") and values-ldltr (means "layout-direction-left-to-right").
Declare in your app manifest that your app supports RTL mirroring.
Specifically, add android:supportsRtl="true" to the <application> element in your manifest file and set targetSdkVersion to 17 or higher.
In Settings of my Android app, I use many of checkboxPreferences. When the locale selected is English, text appears at the Left side and Check box at the right side.
Text ------------------Checkbox
When I change locale to Arabic, I want to get this format:
Checkbox---------------Text
But it keeps the same as English locale. I don't know what to do. Can someone help me?
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. Add android:supportsRtl="true" to the element in your manifest file.
Change all of your app's "left/right" layout properties to new "start/end" equivalents.
For more details follow the link
Use RelativeLayout as the parent layout and then add layout_alignParentStart or layout_alignParentEnd attributes for Text / Checkbox views.
Please note, this only works from API v17 on.
What is the best way to provide the ability to switch between hebrew/english layouts in Android applications?
Is it commonly done - or usually just providing hebrew or english applications.
I know there is abikty to use localiztions - but is there Hebrew support for this?
Also my application should be for iPhone as well and I want to keep it the same.
How should do it in the code? Where to place the layouts?
Yoav
For orientation (right-to-left) you need: android.text.Layout.Direction
A hebrew TrueTypefont can then be called from a resource in your app by including TextView.
Instead of pushing 2 layout files you could use a class for hebrew and another for english...
or you could push the text to string values file for highest cleanliness
If it is a block of text that could be called from resource txt file (practical for prayers)
It all depends on how much text you have.