我从远程服务器加载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 ```
这个问题的解决方案是什么?