我正在尝试从Web视图中的assets文件夹加载本地js文件。
它在Android 4.4.4和Android 5下完美运行,但在Android 4.3及更低版本下无效。
css显示正确,但似乎没有加载js。
这是我的代码:
private static final String HTML_CHARSET = "<meta charset='utf-8'>";
private static final String HTML_TITLE = "<title>Aufbau einer Tabelle</title>";
private static final String HTML_STYLESHEET = "<link href='matrix.css' type='text/css' rel='stylesheet'/>";
private static final String HTML_SCRIPT1 = "<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js' type='text/javascript'></script>";
private static final String HTML_SCRIPT2 = "<script src='https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js' type='text/javascript'></script>";
private static final String HTML_SCRIPT3 = "<script src='matrix.js' type='text/javascript'></script>";
private static final String HTML_VIEWPORT = "<meta name='viewport' content='width=device-width, initial-scale=1.0'>";
private static final String HTML_STRING = "<!doctype html> <html> <head> " + HTML_CHARSET + HTML_TITLE + HTML_STYLESHEET + HTML_SCRIPT1 + HTML_SCRIPT2 + HTML_SCRIPT3 + HTML_VIEWPORT + "</head> <body> <table> %s%s </table> </body> </html>";
...
String htmlString = String.format(HTML_STRING, htmlTableHeader, tableBody);
WebSettings settings = matrixWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
matrixWebView.loadDataWithBaseURL("file:///android_asset/", htmlString, "text/html", "UTF-8", null);
有人有想法吗?
答案 0 :(得分:0)
loadDataWithBaseURL不需要以“file://”为前缀或路径。它只需要HTML内容。
loadURL可用于加载文件内容。