Webview 加载活动列表在在部分手机上空白显示,尝试的几种方式。
1、xml的WebView标签中添加android:layerType="hardware"
2、xml的WebView标签中添加android:layerType="software"
3、WebViewActivity中添加
protected void onDestroy() {
Logger.i("WebViewActivity onDestroy:", "webView:" + webView);
CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); CookieSyncManager.getInstance().sync();
if (webView != null) {
webView.setWebChromeClient(null);
webView.setWebViewClient(null);
webView.getSettings().setJavaScriptEnabled(false);
webView.clearCache(true);
webView.removeAllViews();
webView.destroy();
}
super.onDestroy();
}
4、 LoadUrl时,设置以下:
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setJavaScriptEnabled(true);//设置能够解析JavaScript
webView.getSettings().setSupportZoom(true); // 支持缩放
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); // 不加载缓存
webView.getSettings().setDomStorageEnabled(true);//设置适应HTML5的一些方法
webView.getSettings().setAppCachePath(getApplicationContext().getCacheDir().getAbsolutePath());
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
5、
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mWebView.setLayerType(View.LAYER_TYPE_HARDWARE,null);
}
6:在onPause()中加上这句
mWebView.loadUrl("about:blank");
WebSettings settings =webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDefaultTextEncodingName("utf-8");// settings.setAppCacheEnabled(false); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); settings.setDomStorageEnabled(true);//设置适应HTML5的一些方法// settings.setBuiltInZoomControls(false);// settings.setAllowFileAccess(true);// settings.setUseWideViewPort(false);// settings.setLoadWithOverviewMode(true);// if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){// settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);// }
String call ="javascript:getUserToken('"+token+"')";
String call ="javascript:getUserToken('tokendf')";
webView.loadUrl(call);
网友评论