Text view displays Arabic characters as question marks “?????”

放肆的年华 提交于 2019-12-11 05:15:47

问题


I'm working on an android app that displays a textviews with mixed Arabic and English words;

the app displays Arabic text that I wrote inside Java classes as question marks ????? here is a screenshot:

The Code:

if(tCat.equals("StandardT_")){
     serviceLine="Operations / خدمات عامة";
 }
tv.setText(serviceLine);

what I have tried:

  1. Decoding characters in android and no its not the same question and the answers didn't help.

  2. How to support Arabic text in Android? I'm using a new version that supports Arabic and I also tried the answer like adding Farsi Class or using ArabicUtilities classes but that didn't work ether

  3. I also tried to encode String into utf-8

    try { serviceLine= URLEncoder.encode(serviceLine, "utf-8");} catch(UnsupportedEncodingException e){ e.printStackTrace(); }

and that didn't work!

  1. also tried using multiple fonts but not a single Typeface solved the problem.

So I'm kind of stuck here, any ideas?

Edit: After I closed android studio and reopened the app all of the text that I wrote inside the Java classes turned to question marks! Even though I tried to write it again, once I closed the project and reopened it, it displays the Arabic text as question marks inside the Java classes before even I run the application and this is really awkward!


回答1:


You need to set the file encoding of the file that contains the arabic text to UTF-8.

This is how you change file encoding from inside Android-Studio.



来源:https://stackoverflow.com/questions/31178878/text-view-displays-arabic-characters-as-question-marks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!