Android WebView加载白屏解决方案

    android:id="@+id/web_view"
    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:layerType="hardware"/>



mView = (WebView) findViewById(R.id.web_view);
WebSettings settings = mView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setAppCacheEnabled(true);
//设置可以访问文件  
settings.setAllowFileAccess(true);


mView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
Log.d("view.getTitle()", "view.getTitle()" + view.getTitle());
if(Valids.isEmpty(titleName)){
titleTextView.setText(view.getTitle().toString());
}else{
titleTextView.setText(titleName);
}
mView.setLayerType(View.LAYER_TYPE_HARDWARE,null);

}


@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}






/* @Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(s);
return true;
}


@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
handler.proceed();
}*/
});


mView.loadUrl(s);



@Override
protected void onPause() {
super.onPause();
mView.reload();//退出时关闭声音
Log.d("on", "onStart=="+"onPause");
mView.loadUrl("about:blank");
}

你可能感兴趣的:(WebView)