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", "");
Community
  • 1
  • 1
Khalid ElSayed
  • 278
  • 1
  • 5
  • 20

1 Answers1

0

I am facing the same issue here, I am using an HTML file with a CSS file using the @font-face tag, but I have done further testing:

  1. I tried the same code with custom western fonts and it was successful.
  2. I hosted the file on my PC on IIS and accessed it from Chrome for desktop, it successfully loaded the custom Arabic font, Android Chrome on the other hand failed to load the custom Arabic font (the same for webview and Internet application).

Regards.

Kumait
  • 702
  • 8
  • 15