WebView最佳配置

来源:互联网 发布:linux root登陆 编辑:程序博客网 时间:2024/06/03 17:46

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);       }
0 0
原创粉丝点击