【问题标题】:Decoding Urdu Codes in Android在 Android 中解码乌尔都语代码
【发布时间】:2016-02-02 07:29:13
【问题描述】:

我正在调用 API 并接收英语和乌尔都语的响应。响应存储在字符串中,乌尔都语部分显示字符文本,如“/u024/”。

我一直在实现这个代码集,它给出的结果与以前的 urdu 字符相同。如果有人可以帮助我解决这个问题,请帮助我

    String fontPath = "urdu.ttf";

    // text view label
    TextView txtGhost = (TextView) findViewById(R.id.ghost);

    // Loading Font Face
    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);

    // Applying font
    txtGhost.setTypeface(tf);

【问题讨论】:

    标签: android fonts arabic android-typeface urdu


    【解决方案1】:

    试试这个字体,而不是你当前的字体:http://www.quran.or.kr/urdu/font/asunaskh.ttf

    try {
        txtGhost.setTypeface(Typeface.createFromAsset(this.getAssets(),"asunaskh.ttf"));
        txtGhost.setText("ur text");
    }
    catch(Exception ex) {
        Log.e("TAG", ex.toString());
    }
    

    那么,您的案例中出现了哪些错误?

    有关语言支持的更多信息:how to add language support to android

    【讨论】:

      【解决方案2】:

      您的 Unicode 回复, 试试这个

      TextView tv=(TextView)findViewById(R.id.textViewmyView);
      final Typeface tf = Typeface.createFromAsset(this.getAssets(),"asunaskh.ttf");
      tv.setTypeface(tf);
      tv.setText(Html.fromHtml(yourText);
      

      如果上述方法不起作用,请添加此内容

      String str = myString.split(" ")[0];
      str = str.replace("\\","");
      String[] arr = str.split("u");
      String text = "";
      for(int i = 1; i < arr.length; i++){
      int hexVal = Integer.parseInt(arr[i], 16);
      text += (char)hexVal;
      }
      

      或者这个

      textview.setText(Html.from(StringEscapeUtils.unescapeJava(unicode))); //this method
      

      更多信息:见How to use unicode in Android resource?

      How to convert a string with Unicode encoding to a string of letters

      【讨论】:

      • 为什么要在设置文字后设置字体?
      • 顺便说一句,它没有成功。 {"成功":"100","消息":"成功","姓名":"\u0645\u062d\u0645\u062f \u0639\u0628\u062f\u0627\u0644\u0644\u0647\u0627\u0639\u0638 \u0645 \u062e\u0627\u0646"} 这是API的准确返回,存储在一个字符串中,\u062f\等部分是乌尔都语字符。
      • 无论你存储什么都没有关系,如果字符串中的任何单词/字符是 UTF/html 格式,那么它将自动转换为 html\
      • 我已尝试您发布的第二个代码,但应用程序因未知原因崩溃。在 logcat 上也找不到任何东西
      • 让我试试很快就会给你解决方案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多