2013-11-21 83 views
2

我從遠程服務器加載html文件並在webview中顯示它們,但我的語言的默認字體有點亂,所以我嘗試從資源文件夾加載字體。這裏是我的java代碼和html文件。從資產文件夾中加載字體

webView.getSettings().setAppCacheEnabled(false); 
webView.getSettings().setAppCacheMaxSize(1); 
webView.getSettings().setDomStorageEnabled(true); 
webView.addJavascriptInterface(new WebAppInterface(this), "Android"); 
webView.setWebViewClient(new MyWebViewClient()); 
isShowing=true; 
dialog.show(); 
String address="http://server/test.html"; 
Log.d("checking", address); 
webView.loadUrl(address); 

的html代碼:

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 


<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title> Title Here </title> 

    <style type="text/css"> 
    @font-face { 
     font-family:nazanin; 
     src:url('file:///android_asset/fonts/BNAZANIN.TTF'); 
    } 

    body { 
     font-family: nazanin; 
     font-size: medium; 
     text-align: justify; 
    } 

</style> 

</head> 

<body> 

    <p>this is for test</p> 

</body> 
</html> 

問題是裝載後,我得到這個錯誤:

11-21 10:50:55.439: E/Web Console(9572): Not allowed to load local resource: file:///android_asset/fonts/BNAZANIN.TTF at :0

究竟是什麼解決辦法嗎?

+0

這個問題被錯誤地標記爲重複,OP想要訪問一個字體,從一個外部網頁的webview,不讀取與本地.html文件的webview作爲重定向...方式去社區.. 。 – desgraci

回答

0

我最終在服務器上添加該字體並鏈接到html文件中的字體。我嘗試了幾乎任何方法,我認爲這是唯一可行的方法。 LoadDataWithBaseUrl和在資產文件夾中添加字體不是當您在html中使用外部文件(如css和js)時的方式。

相關問題