Text view shows Arabic sentence disabled

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

I nested it in "String.xml" and used it in my code:

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

      

But android displays it as text like this (not connected):

enter image description here

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

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

      

It is then printed, corrected to logcat.

I am a little confused as to why it is not displayed as text correctly. Please help me find a solution to this problem.

+1


source to share


1 answer


I solved this problem 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 mail folder from the first link 2. Put in the package two classes named "ArabicReshaper" and "ArabicUtilities" and change the package name to our application package name

  1. After that put this code in 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 need to download "tahoma.ttf" and place it in the assets folder.

+1


source







All Articles