android webview javascript不执行,Android Webview Javascript – 对脚本的引用不起作用
我设法通过以下方式做了类似的事情:WebView webView = (WebView) findViewById(R.id.webview);WebSettings webSettings = webView.getSettings();webSettings.setJavaScriptEnabled(true);webSettings.setDomStorageEnabled(true);we
我设法通过以下方式做了类似的事情:
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样式表:
Input something in the input Box:
Name:
另外,我的文件结构如下
希望能帮助到你 :)
更多推荐
所有评论(0)