roy mathew
roy mathew

Reputation: 7800

Text view shows Arabic sentence in a disconnected way

I am trying to display a sentence in Arabic. For testing it I have used Google translator and found out the equivalent sentence in Arabic for "Hello World" which is مرحبا العالم

I have pasted it in "String.xml" and used it like this in my code:

txt1.setText(getResources().getString(R.string.sample_arabic_text));

But android is displaying it in text view like this (not in a connected way):

enter image description here

Then I tried to print the content of the text view like this:

System.out.println(txt1.getText());

Then it printed corrected in logcat.

I am bit confused why it is not getting displayed in text view correctly. Please help me to find a solution for this issue.

Upvotes: 1

Views: 2545

Answers (1)

roy mathew
roy mathew

Reputation: 7800

I solved this issue by putting two classes from this link:

https://github.com/agawish/Better-Arabic-Reshaper

and following the instructions in this link:

http://blog.amr-gawish.com/39/arabic-language-in-android/

Steps:

1.Download the zip folder from first link 2. Put the two classes named "ArabicReshaper" and "ArabicUtilities" in to the package and change the package name to our application's package name

  1. After that put this code in the on create from the second link:

    AssetManager manager=this.getAssets();

    manager.open("tahoma.ttf");
    TextView tv=(TextView)this.findViewById(R.id.testMe);
    tv.setTypeface(Typeface.createFromAsset(manager, "tahoma.ttf"));
    tv.setTextSize(50f);
    tv.setText(ArabicUtilities.reshape("adsdads الحمد لله asdad"));
    

Note: We have to download "tahoma.ttf" and put in the asset folder.

Upvotes: 1

Related Questions