//开启Javascript 支持
final WebSettings webSettings = webView .getSettings();
webSettings.setDomStorageEnabled(true);// 在js加载完再进行操作,否则会出现 js 函数错误
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
//自适应
webSettings.setUseWideViewPort(false);//设置此属性,可任意比例缩放
webSettings.setLoadWithOverviewMode(true);
//
webSettings.setBuiltInZoomControls(true);
webSettings.setSupportZoom(true);
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setAppCacheMaxSize(1024 * 1024 * 8);
// webView.addJavascriptInterface(new Object() {
// public void clickOnAndroid() {
// handler.post(new Runnable() {
// public void run() {
// webView.loadUrl("javascript:wave()");
// }
// });
// }
// }, "demo");
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
webView.requestFocus();//为了使得webview对触屏做出反应,获取焦点
return false;
}
});
可以对网页加载过程进行控制利用一下接口
WebChromeClient webChromeClient = new WebChromeClient(){ @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress > 50 && pd.isShowing()){ pd.dismiss(); } } };