webview 简单应用

来源:互联网 发布:diffrac.eva软件下载 编辑:程序博客网 时间:2024/04/30 13:31
/* // 加载页面
WebView webView = (WebView) findViewById(R.id.webview);
// 允许JavaScript执行
webView.getSettings().setJavaScriptEnabled(true);
// 找到Html文件,也可以用网络上的文件
// webView.loadUrl("file:///android_asset/index.html");
// webView.loadUrl("http://www.baidu.com");
StringBuffer sb = new StringBuffer();
sb.append("");
sb.append(" <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> ");
sb.append("<html>");
sb.append(" <head>  ");
sb.append(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">  ");
sb.append(" </head>  ");
sb.append(" <body onload=\"javascript:contact.showcontacts()\">  ");
sb.append(" <img src = \"file:///android_asset/barcode.png\" />");
sb.append(" </body>  ");
sb.append("  </html>  ");
// webView.loadUrl("file:///android_asset/index.html");
webView.loadDataWithBaseURL("about:blank", sb.toString(), "text/html", "utf-8", null);*/
0 0