WebView显示加载对话框?

时间:2016-12-05 17:26:32

标签: android

我不确定为什么onPageFinished在加载页面时没有踢它?加载对话框只是继续显示,尽管页面已加载如何修复它?

我想在页面加载后对话框消失!

   public class MainActivity extends Activity {
        WebView web;
        ProgressDialog dialog;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            //Hide Title Bar    - This Should be done before SetContentView

            this.requestWindowFeature(Window.FEATURE_NO_TITLE);

            setContentView(R.layout.activity_main);
            // Inflation

            web = (WebView) findViewById(R.id.webview);

            web.setWebViewClient(new WebViewClient() {

                // This method will be triggered when the Page Started Loading

                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    dialog = ProgressDialog.show(MainActivity.this, null,
                            "Please Wait...Page is Loading...");
                    dialog.setCancelable(true);
                    super.onPageStarted(view, url, favicon);
                }

                // This method will be triggered when the Page loading is completed

                public void onPageFinished(WebView view, String url) {
                    dialog.dismiss();
                    super.onPageFinished(view, url);
                }




            });
            web.loadUrl("http://google.com");
            web.getSettings().setLoadWithOverviewMode(true);
            web.getSettings().setUseWideViewPort(true);
            // enabling javaScript
            WebSettings webSettings = web.getSettings();
            webSettings.setJavaScriptEnabled(true);
        }
    }

0 个答案:

没有答案