我设法通过以下方式做了类似的事情:

WebView webView = (WebView) findViewById(R.id.webview);

WebSettings webSettings = webView.getSettings();

webSettings.setJavaScriptEnabled(true);

webSettings.setDomStorageEnabled(true);

webView.setWebChromeClient(new WebChromeClient());

try {

String html = readAssetFile("www/index.html");

webView.loadDataWithBaseURL("file:///android_asset/www/",html,"text/html","UTF-8",null);

} catch (IOException e) {

}

‘readAssetFile’在哪里:

private String readAssetFile(String fileName) throws IOException {

StringBuilder buffer = new StringBuilder();

InputStream fileInputStream = getAssets().open(fileName);

BufferedReader bufferReader = new BufferedReader(new InputStreamReader(fileInputStream,"UTF-8"));

String str;

while ((str=bufferReader.readLine()) != null) {

buffer.append(str);

}

fileInputStream.close();

return buffer.toString();

}

此外,我的页面很简单 – 只是为了测试图像,angularjs lib和css样式表:

De nada

Input something in the input Box:

Name:

另外,我的文件结构如下

希望能帮助到你 :)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐