webview最佳配置:
mWebView = (BridgeWebView) findViewById(R.id.main);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true); // 启用js
settings.setJavaScriptCanOpenWindowsAutomatically(true); // js和android交互
String cacheDirPath = getApplicationContext().getCacheDir().
getAbsolutePath();
settings.setAppCachePath(cacheDirPath); // 设置缓存的指定路径
settings.setAllowFileAccess(true); // 允许访问文件
settings.setAppCacheEnabled(true); // 设置h5的缓存打开,默认关闭
settings.setUseWideViewPort(true); // 设置webview自适应屏幕大小
settings.setLoadWithOverviewMode(true); // 设置webview自适应屏幕大小
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);//设置,可能的话使所有列的宽度不超过屏幕宽度
settings.setDomStorageEnabled(true); // 设置可以使用localStorage
settings.setSupportZoom(false); // 关闭zoom按钮
settings.setBuiltInZoomControls(false); // 关闭zoom
mWebView.loadUrl("file:///android_asset/bb2/babyform.html");
关闭硬件加速:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}