1.先加载文字,再加载图片
WebSettings settings = mWebView.getSettings();
settings.setBlockNetworkImage(true);
mWebView.setWebChromeClient(new BaseWebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress == 100) {
// 网页加载完成
settings.setBlockNetworkImage(false);
} else {
// 网页加载中
}
}
}
2.设置相关缓存
WebSettings settings = mWebView.getSettings();
// 设置支持本地存储
settings.setDatabaseEnabled(true);
//设置存储模式
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setAppCacheMaxSize(20*1024*1024);
settings.setAppCacheEnabled(true);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setDomStorageEnabled(true);
3.加载url放在主线程
runOnUiThread(new Runnable() {
@Override
public void run() {
mWebView.loadUrl(mUrl);
}
});