您的位置:首页 > 移动开发

WebView最佳配置

2016-02-02 15:14 357 查看
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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  webview 配置