Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text align problem when using Arabic font

The screenshot below displays my problem.

The first EditText shows a hint in Arabic which is shifted upwards, now the second EditText is just for reference which shows the English version completely fine. Same goes for the Button.

I have declared the string in strings.xml like this:

<string name="ar_login">دخول</string>

screenshot of the problem

This is how I set the EditText's hint:

UserName.setTypeface(ArabicFont);
String hint = getString(R.string.ar_HintUserName);
....
UserName.setHint(hint);

UPDATE: I used this, but of no use:

UserName.setGravity(Gravity.CENTER_VERTICAL);

But with this, Text moved a little down; but i guess its not generic:

UserName.setPadding(0,15,0,0);

With Padding, English words move to downwards.

UPDATE 2: Originally arabic texts are separated; means they are shown letter by letter. So to join them, i was using this Arabic Reshaper. To Download Code, Check this link

Now when i reshape the arabic text and then set on TextView or as EditText's Hint, it got shifted upwords but without reshaping it is fine.

So i guess, whether i have to change the reshape class OR make my textview to not split the word. But dont know where to go?

like image 788
Farhan Avatar asked Jun 28 '11 10:06

Farhan


People also ask

Is Arabic text right aligned?

Arabic language is a right to left language (RTL) which means writing starts from the right and continues to the left. However, when text is right-justified explicitly, it should have the same alignment as English.

Can you center align Arabic text?

translated arabic text cannot be aligned properly, arabic is written from right to left, and there was no way to format it properly even top alignment as u can see.

What is font and alignment?

Text alignment is a paragraph formatting attribute that determines the appearance of the text in a whole paragraph. For example, in a paragraph that is left-aligned (the most common alignment), text is aligned with the left margin. In a paragraph that is justified, text is aligned with both margins. Align text left.


1 Answers

I am still unable to find out why Android splits the arabic words into separate letters anyhow in my second edit I am providing a link which uses a class to rejoin the separated letters and form a word again.

In the reshape function, it was mistakenly appending \n at the end, just removing it solves the problem.

like image 83
Farhan Avatar answered Oct 13 '22 08:10

Farhan