2

I am trying to display Arabic text in an Android application, however the Arabic text is displayed as ???.

it works fine when i set the text of a TextField directly from xml file using android:text="مثل", but when i try to set it from Java code mTextView.setText("مثل");, it displays as question marks character (???).

According to this answer How to support Arabic text in Android?, Arabic is supported for Android 3.x and above.

Community
  • 1
  • 1
T-D
  • 373
  • 8
  • 21
  • make sure your java files are saved in UTF-8 encoding. Not sure about arabic, but cyrrillic fonts are displayed properly – injecteer Jul 08 '15 at 21:30
  • @injecteer do you mean i should manually change the encoding (save as) of the java files to UTF-8 ? – T-D Jul 08 '15 at 21:42
  • yepp, your IDE must be using some other encoding by default. – injecteer Jul 08 '15 at 22:03
  • @injecteer Well Marcin Orlowski's answer solved the problem. But one should note that it only takes effect after recreating the files. – T-D Jul 08 '15 at 22:04

1 Answers1

2

If android:text works fine and setting from code does not, then most likely your source files (*.java) are not using UTF-8 encoding. You need to check your editor/IDE settings - for Android Studio go to Settings -> Editors -> File Encodings and check files and project encoding.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Changing the Encoding of the IDE doesn't automatically change the encoding of the files. Deleting and recreating the file after setting the proper encoding in the editor solved the problem. Thanks – T-D Jul 08 '15 at 22:03
  • 1
    Just a note, the IDE encoding was set to UTF-8, but the project encoding was set to a different one. – T-D Jul 08 '15 at 22:10
  • Good note. I added to the answer for consistency. – Marcin Orlowski Jul 08 '15 at 23:08