I'm developing an application for Android in Persian. I fetch data from SQLite database and display them, using TextView. How can I display the text (that contains multiple lines ) from right to left?
Any Idea?
If the ROM supports right-to-left, which is most likely the case if you bought your mobile in the middle east, then you can set the gravity to right.
If Android does not support this natively (I'm not sure), you could create a string reverser that swaps the nth char with the string.length() - nth character until you have a reflected string, and then post that right justified.
If the ROM doesn't support right-to-left rendering, you could possibly use the java.text.Bidi class that implements the Unicode Bidi Algorithm.
This is an old question but since it wasn't asked very good it was not answered.
#Farina, I believe the answer you are looking for is here:
http://developer.android.com/guide/topics/resources/providing-resources.html
In essence: By creating a layout-ar folder right next to your layout folder and placing an rtl oriented layout file in it you can get it to show only on rtl selected devices. (ar stands for Arab, if using a different rtl language you may find the code here. Be-were that some devices support old-deprecated language codes so if it doesn't work try looking for older codes)
Related
I actually wand to type Arabic,Is it possible ?
I am creating an android application.And i am new to it.please help.
i tried these code it didn't work.
if(UTILSSessionVariables.LCID==2057)
{
setContentView(R.layout.passportdocumentfields);
LastName.setGravity(Gravity.LEFT);
}
else if(UTILSSessionVariables.LCID==3801)
{
setContentView(R.layout.arabicpassportdetails);
LastName.setGravity(Gravity.RIGHT);
}
Use a Bidi object to get the information on the position reordering of a bidirectional text, such as Arabic or Hebrew. The natural display ordering of horizontal text in these languages is from right to left, while they order numbers from left to right.
Read the below document :-
http://developer.android.com/reference/java/text/Bidi.html
or
android:textDirection="anyRtl"
http://android-developers.blogspot.in/2013/03/native-rtl-support-in-android-42.html
If the locale of the phone is set to a right to left language, it will do this automatically. At least for all phones 4.0 and higher. Before then there was actually a special patch to the framework that provided that feature that was applied to all phones going to RTL regions, which means it would work on 2.3 phones from those areas, but not on phones without the patch. Of course this means phones without that patch just won't work and there's no real way to fake it, since AFAIK there's no way to tell if the phone has the patch or not.
I want to create a HUD speed counter using Qt and my smartphone. I can get speed via gps information, the issue is when I display it on the screen, I can't manage to display the QLabel mirrored.
So here's my question : Who can I write from right to left ?
As asked by Samoth i post my comment as an answer ;)
This is helpful resource for mirroring QLabel: http://qtcentre.org/archive/index.php/t-8248.html
Not sure if it answers your question. The following resources demonstrate how to display RightToLeft Text in Qt / QLabel:
Qt 4.7 Desktop application support for right-to-left UI (Hebrew)
Display a Hebrew RTL label - howto?
I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.
I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.
Can someone help me about it?
Thanks
I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.
If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.
Typeface myfont = Typeface.createFromAsset(getAssets(),
"fonts/Blocks2.ttf");
myeditText.setTypeface(myfont);
The font is in the asset folder under another folder called fonts.
This question is related to How to change letter spacing in a Textview?
As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...
You need to use TextWatcher to achieve visual purpose spaces.
And use any simply split string by space logic to join it back or loop
through the entire string per character wise and eliminate (char) 32
from the string
As far as i know actual character spacing is not possible, though i'd love to use that myself as well.
Another option might be to use a custom font with the character spacing included.
I'm working on a relatively simple Android app. I want it to have an English version as well as a Hebrew version. (RTL Right to Left Alignment)
I have manually change the alignment to right in layout xml file. When a sentence contains digits (in the middle of it), the digits appear in a mirror view:
29 appears as 92, 21:45 appears as 54:12 and 2,000 appears as 000,2.
Also, when a sentence starts with digits or English characters, they get thrown to the end of the sentence messing it all up.
I think for android version 4.0.3 it supports Hebrew. I have check that in emulator.
So for older versions is there correct way to implement Hebrew?
Please help.
I think that Android's bidi analysis algorithm has some flaws. Unicode has two invisible, strongly directional characters that might help with these problems:
U+200E - left-to-right mark
U+200F - right-to-left mark
For the digit order problem, try putting left-to-right marks (U+200E) on both sides of the digit sequence.
Unicode also has the following bidi formatting codes:
U+202A - left-to-right embedding
U+202B - right-to-left embedding
U+202C - pop directional formatting (cancels the previous embedding or override)
U+202D - left-to-right override
U+202E - right-to-left override
For the problem with English fragments in Hebrew text, it might be as simple as putting a right-to-left mark before the English. (Android's algorithm may be under the impression that the paragraph is left-to-right since the first characters are English.) If that doesn't work, perhaps try surrounding selected text with some combination of formatting codes. (I'd try left-to-right embedding followed by pop directional formatting. I'd also try right-to-left embedding around everything combined with selective explicit right-to-left embeddings.)
The way these are supposed to affect text layout are defined by the Unicode Bidirectional Algorithm Unicode Standard Annex #9. However, if Android's implementation is broken (and I suspect it is), the best you can do is trial-and-error until you get things looking right. Good luck.
EDIT
As far as code is concerned, here's an example of how it might be done in Java:
String text = "גרסה \u200e2.100\u200e זמינה";
In XML, it might be:
<string name="update_available">גרסה 2.100 זמינה</string>
here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:
you need to add '\u200e' before the char that causes you the problem:
<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>
and the result will be:
:המר על תוצאת המשחק
I want to be able to run a "Hello World" application on my android emulator in hebrew
How can I do that? is it supported?
thanks
Though android does not have complete support for Hebrew if you are just displaying text, then it turns out to be pretty easy to do.
First you want to add a Hebrew font to your app. For this you simply put a true type font file (with Hebrew characters) in your assets directory. Then you load the font and use it on your view. For any view that inherits from TextView (which includes just about any view that displays text), you do the following:
AssetManager assets = getAssets();
Typeface font = Typeface.createFromAsset(assets, "hebrewfont.ttf");
view.setTypeface(font);
This will cause Hebrew characters to be visible. You may need to use the RTL mode character (\u200F) to force your text to display in the correct order. You may also need to set the gravity to right in order to right align the text.
I've found no way to get the scrollbar to appear on the left side. :( Cantilation marks to however display properly starting in android 2.2. I've tested Nequdot in all versions since 1.5, and they work as well. You may want to use some of the precombined characters, such as shuruq (\ufb35) instead of vav+dagesh (\u05d5\u05bc), as this isn't necessarily handled properly.
I have had good results with the DejaVu font, which is freely available.
Although this has been asked a long time ago, there is a native Hebrew support in later versions. The avd with API15 (Android 4.0.3) can display Hebrew nicely out of the box. I'm not sure which version is the earliest with this capability.