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 とインターネット アプリケーションでも同じです)。

よろしく。

于 2013-05-06T10:21:36.357 に答える