我需要显示一个包含Webview
的网站页面,但页面全是白色的,我得到:nativeOnDraw failed; clearing to background color.
为什么呢? 我也尝试过:
webView = (WebView) findViewById(R.id.webView);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
但是我遇到了同样的问题。
答案 0 :(得分:1)
在清单文件集中:
<application
android:hardwareAccelerated="true"
.
./>
然后在你的活动中:
webView = (MyWebView) findViewById(R.id.webView);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setAllowFileAccess(true);
if (Build.VERSION.SDK_INT >= 16) {
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
}
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setUseWideViewPort(false);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setGeolocationEnabled(false);
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// chromium, enable hardware acceleration
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
// older android version, disable hardware acceleration
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}