3

I have a webview which has an arabic content and I've tried to change the default font with custom one (which is an arabic font) as described here but with no success. So how can i do that?

any help will be appreciated.

Edit: this is my code:

// Prepare html page
String fontFamily = "@font-face {"
        + "font-family: 'ARABTYPE';"
        + "src: url('file:///android_asset/fonts/ARABTYPE.TTF');} "
        + "body {font-family: 'ARABTYPE';font-size: large;text-align: justify;}";

    String mHTMLHeader = "<html><head><style type=\"text/css\">\n"
            + fontFamily + "\n</style></head><body><div dir='rtl'>";

    String arabicText = "السلام عليكم ورحمة الله";

    String mHTMLFooter = "</div></body></html>";

    String mHtml = mHTMLHeader + "<div dir='rtl'>" + arabicText
            + "</div>" + mHTMLFooter; 

    WebView mBrowser;

    mBrowser = (WebView) findViewById(R.id.myWebView);

    mBrowser.getSettings().setSupportZoom(true);
    mBrowser.getSettings().setBuiltInZoomControls(true);
    mBrowser.getSettings().setJavaScriptEnabled(true);
    mBrowser.getSettings().setDisplayZoomControls(false);

    mBrowser.loadDataWithBaseURL("file:///android_asset/", mHtml, "text/html", "UTF-8", "");
4

1 回答 1

0

我在这里面临同样的问题,我正在使用带有 @font-face 标记的 CSS 文件的 HTML 文件,但我已经做了进一步的测试:

  1. 我用自定义西方字体尝试了相同的代码,它成功了。
  2. 我在 IIS 上将文件托管在我的 PC 上并从桌面版 Chrome 访问它,它成功加载了自定义阿拉伯字体,另一方面,Android Chrome 未能加载自定义阿拉伯字体(对于 webview 和 Internet 应用程序也是如此)。

问候。

于 2013-05-06T10:21:36.357 回答