【问题标题】:webview justify not show Persia(Farsi)/RTL Language Correctlywebview 证明不能正确显示波斯(波斯语)/RTL 语言
【发布时间】:2014-07-21 22:24:37
【问题描述】:

我需要证明 webview 显示波斯语(波斯语)/RTL 字符串。

我使用下面的代码:

    String text = "<html><body>"
                      + "<p align=\"justify\">"                
                      + getString(R.string.test1) 
                      + "</p> "
                      + "</body></html>";
            webView.loadData(text, "text/html", "utf-8");

但 webview 无法显示波斯字符 - 下图:

我该怎么办?

【问题讨论】:

  • @Dev-iL ,所以 tanx 很有帮助 - 只是,我如何在文本中使用“\n”在 webview 中显示 - 我使用“\n”但显示“\n”没有新的行!
  • 我相信在 html 中换行是由 '
    '
  • @Dev-iL,对,但是我从“getString(R.string.test1)”读取数据,在这个解决方案中我必须写字符串,我不能从 string.xml 读取数据跨度>

标签: android webview text-justify right-justified


【解决方案1】:

好的,最后我找到了一个很好的方法来证明 + 使用 "\n" + 所有其他自定义字符串。

  1. 我制作了一个包含自定义字符串的 HTML 文件
  2. 以这种方式将数据加载到WebView:

    webView.loadUrl("file:///android_asset/string.htm");
    

编辑:

webView.loadDataWithBaseURL(null, yourString, "text/html", "utf-8", null);

【讨论】:

    【解决方案2】:

    加载数据使用

    webView.loadData(text, "text/html; charset=UTF-8", "utf-8"); 
    

    默认情况下不支持 RTL。要修复它,我使用 HTML 标记:

    String headerText = "<html><body dir=\"rtl\"; style=\"text-align:justify;background-color:#fff3eb;\">";
    

    在字符串末尾添加:

    String footerText = "</body></html>";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2013-07-28
      相关资源
      最近更新 更多