安卓webview详情(软件加速跟硬件加速)
当我们在使用WebView时,如果加载的网页比较大有很多的图片,如果没有在webview中使用加速器有些手机就会出现闪退出的问题这时就要启动加速器去进行渲染
webView = (WebView) findViewById(R.id.activity_broad_cast_details_wv_detail); WebSettings ws = webView.getSettings(); ws.setUseWideViewPort(true); ws.setLoadWithOverviewMode(true); ws.setSavePassword(true); ws.setSaveFormData(true); ws.setJavaScriptEnabled(true); ws.setGeolocationEnabled(true); ws.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/"); ws.setDomStorageEnabled(true); ws.setSupportMultipleWindows(true); ws.setJavaScriptEnabled(true); webView.getSettings().setPluginState(PluginState.ON); if (Build.VERSION.SDK_INT >= 19) {//硬件加速器的使用 webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else { webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } xwebchromeclient = new myWebChromeClient(); webView.setWebChromeClient(xwebchromeclient); // 设置Web视图 webView.setWebViewClient(new IntimateServeActivityViewClient()); webView.loadUrl(url);// private class IntimateServeActivityViewClient extends WebViewClient { @Override public void onPageFinished(WebView view, String url) { //super.onPageFinished(view, url); webView.setLayerType(View.LAYER_TYPE_NONE, null);//如果渲染后有视频播发 就得把加速器关闭了 } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }
以上内容是本人的理解要是有错欢迎交流我的qq号:534992085
相关推荐
xfcyhades 2020-11-20
86417413 2020-11-25
83206733 2020-11-19
86276537 2020-11-19
83266337 2020-11-19
86256434 2020-11-17
zhouboxiao 2020-11-16
rise 2020-11-22
sssdssxss 2020-11-20
windle 2020-11-10
孙雪峰 2020-10-30
85477104 2020-11-17
liuxudong00 2020-11-19
cheidou 2020-11-19
gunhunti 2020-09-25
csdnYF 2020-11-15
达观数据 2020-11-11
playlinuxxx 2020-11-11