Farhan
Farhan

Reputation: 13390

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?

Upvotes: 12

Views: 4471

Answers (3)

Farhan
Farhan

Reputation: 13390

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.

Upvotes: 3

Chandan Adiga
Chandan Adiga

Reputation: 576

I am sure its problem with the font file which you are using.!

[Sorry I am not allowed to upload the screen shot as my reputations are lower :(]

For the layout, I was setting text in xml, and typeface in code. And I'm not setting any attributes like padding/gravity. But it was working fine for me.

So, I can assure you that using font file whose style matches your requirement will solve your problem.

Just to help you out with, but 'm not sure I got font file from DroidSansFallback.ttf

Upvotes: 1

Chandan Adiga
Chandan Adiga

Reputation: 576

Just a guess :) ...,

  1. What if the size of the Arabic font is lower? [If this is the case, then Gravity.CENTER_VERTICAL should have worked for you :( ]

  2. May be this is the style of that font file. How about trying a different font file for Arabic text ?

Upvotes: 0

Related Questions