为WebView增加读取动画

第一步:MainActivity.java
1.import

import android.app.ProgressDialog;
import android.webkit.WebViewClient;
protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

在这之后加入

mProgressDialog = new ProgressDialog(this);
                web_view.setWebViewClient(new WebViewClient(){
                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                                web_view.loadUrl(url);
                                return true;
                        }
                        @Override
                        public void onPageStarted(WebView view, String url, Bitmap favicon) {
                                super.onPageStarted(view, url, favicon);
                                mProgressDialog.setMessage("努力读取中...");
                                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                                mProgressDialog.show();
                        }
                        @Override
                        public void onPageFinished(WebView view, String url) {
                                super.onPageFinished(view, url);
                                mProgressDialog.hide();
                        }
                        @Override
                        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                                super.onReceivedError(view, errorCode, description, failingUrl);
                                web_view.loadUrl("file:///android_asset/error.html");
                        }

发表评论