I've made an app, I've tested it and it was fine on my phone. But... when I gave the .apk to someone else whose phone language is RTL the whole layout broke and it messed up everything.
My question is - How can I force my app to use only LTR and disable the auto layout change which breaks my whole app design?
In your manifest file and inside the application tag add these two lines.
<manifest>
<application
.
.
.
android:supportsRtl="false"
tools:replace="android:supportsRtl" //(replace libraries' Rtl support with ours)
>
</application>
</manifest>
Note: (about second line)
Some libraries have support Rtl in their manifest file so if you want to use those libraries you must replace their manifest line of code with yours.
Android 4.2 added full native support 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
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.
For more precise control over your app UI in both LTR and RTL mode, Android 4.2 includes the following new APIs to help manage View components:
android:layoutDirection — attribute for setting the direction of a
component's layout.
android:textDirection — attribute for setting the
direction of a component's text.
android:textAlignment — attribute
for setting the alignment of a component's text.
getLayoutDirectionFromLocale() — method for getting the
Locale-specified direction
-- Source & Credits --
Just add the following to the manifest
android:supportsRtl="false"
tools:replace="android:supportsRtl"
Just add something like this in your App Theme Style:
<item name="android:layoutDirection">ltr</item>
or
<item name="android:layoutDirection">rtl</item>
For React Native adding the following line in the manifest file was enough:
// android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kidspodmobileclient">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:supportsRtl="false" // <== add this line here
It would be like the following screenshot:
RN version: 0.68.2
Related
I want to localize an image Arabic language? How should I accomplish this task?
I have followed Localization and drawables but no luck.
localization of drawable-resources is same as string-resources. You need to create drawable-ar folder and put image into that folder.
Or if your image in any folder like drawable-mdpi then drawable-ar-mdpi.
Read detail documentation here.
Don't forget that once you've added your strings.xml into the resource file for arabic, ensure your layout is ready for RTL support.
In your manifest file:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:supportsRtl="true" > ....
And in all your layout files, ensure you added the left/right and start/end combo. From Google Blog:
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.
Once you are done, its quite easy to test it out. Either change your language to arabic, or in the phone's Developer Option, you can force it to show RTL in layout.
You can add new android resource folder
I'm using API 17 and I'm looking for a way to set the whole app to rtl instead of using <android:layoutDirection="rtl"> in every single activity layout.
I had the same problem , all you need to do is just consider all your used parent container (LinearLayout , RelativeLayout , GridView , etc) and set the LayoutDirection to RTL you can approach this way programmtically thanks to ViewCompat class to include api lower than 17.
ViewCompat.setLayoutDirection(yourParentContainer,ViewCompat.LAYOUT_DIRECTION_RTL);
note that there is no need to set the Direction for childviews separately
Please check this text extract from android developers weblog:
To take advantage of RTL layout mirroring, simply make the following
changes to your app:
1- Declare in your app manifest that your app supports RTL mirroring.
Specifically, add android:supportsRtl="true" to the
element in your manifest file.
2- 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.
the full text can be found here:
http://android-developers.blogspot.ca/2013/03/native-rtl-support-in-android-42.html
The easiest and best way
go to the app/res/values/styles and add below code to <style> tag, that you defined its name in android manifest
for example :
<style name"YourMainThemeName" parent="Parent Theme Of Your Choice">
<item name="android:layoutDirection">rtl</item>
</style>
and now go to the app/manifests/AndroidManifest.xml and add below line code to <application> tag :
<application
android:supportsRtl="true"
android:theme="#style/YourMainThemeName">
</application>
now your layout directions is rtl.
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"
This question already has answers here:
What is use of android:supportsRtl="true" in AndroidManifest xml file
(4 answers)
Closed 4 years ago.
In Eclipse manifest file , i get a warning message. Application language is Turkish ( Not right to left ).
"The project references RTL attributes, but does not explicitly enable or disable RTL support with android:supportsRtl in the manifest "
I can not add android:supportsRtl line, because my min sdk versionn is 9.
This warning is important?
Thanks
If you do not support RTL (= Right To Left locales), you need to replace all references of start by left and end by right in your xml layouts.
The attributes "start", "end", "paddingStart", "paddingEnd", "android:layout_alignParentStart" etc.. are "RTL attributes" : their meaning depends on the current locale. The risk of not doing this is that if someone sets their system language to Arabic or Hebrew your layouts will be mirrored, even if the text is still displayed in Turkish.
Specifically "start" means "right" if:
the current system language is RTL (Arabic, Hebrew...)
AND the android device is API 17 or higher
AND android:supportsRtl is set to true in the manifest
Otherwise is means "left".
So you get this warning if you have used android:layout_gravity="start" or any start/end attribute in any of your layout and you have not set android:supportsRtl="true" in the manifest.
Note that, if your min SDK is 16 or below and you do not want to support RTL, you actually have to choose one of the warning:
if you do replace start with left you will get the warning :Use "start" instead of "left" to ensure correct behavior in right-to-left locales Id=RtlHardCoded
if you set android:supportsRtl to false: Attribute "supportsRtl" is only used in API level 17 and higher (current min is 9). Id=UnusedAttribute
otherwise: ** The project references RTL attributes, but does not explicitly enable or disable RTL support with android:supportsRtl in the manifest** Id=RtlEnabled
If you do not support RTL, it seems logical to set RtlHardCoded to Info instead of warning.
More info:
http://android-developers.blogspot.co.il/2013/03/native-rtl-support-in-android-42.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+blogspot/hsDu+(Android+Developers+Blog)
http://developer.android.com/guide/topics/manifest/application-element.html#supportsrtl
I used Arabic text so,
I want to write text from right to left so how i can write right to left text in android ?
Regards,
Girish
Try with Bidi
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.
Native RTL support in Android 4.2
It looks like this is only possible starting with jelly bean
use this
android:textDirection="rtl"
android:gravity="right"