webview设置
1 webview.getSettings().setRenderPriority(RenderPriority.HIGH); 2 webview.getSettings().setJavaScriptEnabled(true); 3 webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 4 5 webview.getSettings().setSupportZoom(true); // 支持缩放 6 // webview.getSettings().setBuiltInZoomControls(true); // 显示放大缩小 controler 7 webview.setScrollBarStyle(0); 8 webview.getSettings().setDefaultTextEncodingName("utf-8"); 9 // webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); 10 // // 设置缓存 11 webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); // 不读取缓存,所有内容均从网络下载
1 webview.setWebChromeClient(new WebChromeClient() { 2 @Override 3 public boolean onJsAlert(WebView view, String url, String message, 4 JsResult result) { 5 // TODO Auto-generated method stub 6 return super.onJsAlert(view, url, message, result); 7 } 8 });
1 webview.getSettings().setUseWideViewPort(true);// 關鍵點 2 webview.getSettings().setLoadWithOverviewMode(true); 3 4 DisplayMetrics metrics = new DisplayMetrics(); 5 getWindowManager().getDefaultDisplay().getMetrics(metrics); 6 int mDensity = metrics.densityDpi; 7 if (mDensity == 240) { 8 webview.getSettings().setDefaultZoom(ZoomDensity.FAR); 9 } else if (mDensity == 160) { 10 webview.getSettings().setDefaultZoom(ZoomDensity.MEDIUM); 11 } else if (mDensity == 120) { 12 webview.getSettings().setDefaultZoom(ZoomDensity.CLOSE); 13 } else if (mDensity == DisplayMetrics.DENSITY_HIGH) { 14 webview.getSettings().setDefaultZoom(ZoomDensity.FAR); 15 } else { 16 webview.getSettings().setDefaultZoom(ZoomDensity.FAR); 17 }