我一直在与这个问题争斗超过48小时,我无法在网上任何地方找到答案.这是设置:
我的Android应用程序在首次运行时下载内容(内容超过20MB),文件解压缩到用户的SD卡/ mnt/sdcard/{my package} /文件夹中.内容包括HTML文件,CSS文件,JS文件和图像.这是写入SD卡的完整结构(其中/ =/mnt/sdcard/{my package}/folder /):
/内容/
a.html
b.html
images/
image1.jpg
Run Code Online (Sandbox Code Playgroud)
/ CSS /
c.css
d.css
Run Code Online (Sandbox Code Playgroud)
/ JS /
e.js
f.js
Run Code Online (Sandbox Code Playgroud)
这是我从SD卡加载html文件的代码:
webView = (WebView) findViewById(R.id.pageBrowser);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new LinkHandlerInterface(), "Android");
webView.setWebViewClient(new PageWebViewClient());
// contentLocation + url is equal to the full path to the html file
webView.loadUrl("file://" + contentLocation + url);
Run Code Online (Sandbox Code Playgroud)
此代码成功加载HTML页面.没有问题.每个页面都有以下标题:
<link rel="stylesheet" type="text/css" href="../css/screen.css" media="all" />
<link rel="stylesheet" type="text/css" href="../css/inPractice.css" media="all" />
<link rel="stylesheet" type="text/css" href="../css/inPracticeScheme.css" media="all" />
<link rel="stylesheet" type="text/css" href="../css/mobile/iPad.css" media="all" />
<script type="text/javascript" …
Run Code Online (Sandbox Code Playgroud)