0

在 onProgressChanged(WebView view, int progress) 回调上加载网页时如何获取资源 url?我在这里需要它,因为从缓存加载时,onloadresource 不会在已缓存的资源上调用。谢谢

4

3 回答 3

0

试试这个代码:

final ProgressBar Pbar;
 final TextView txtview = (TextView)findViewById(R.id.tV1);
 Pbar = (ProgressBar) findViewById(R.id.pB1);

MyView.setWebChromeClient(new WebChromeClient() {
      public void onProgressChanged(WebView view, int progress) 
      {
         if(progress < 100 && Pbar.getVisibility() == ProgressBar.GONE){
             Pbar.setVisibility(ProgressBar.VISIBLE);
             txtview.setVisibility(View.VISIBLE);
         }
         Pbar.setProgress(progress);
         if(progress == 100) {
             Pbar.setVisibility(ProgressBar.GONE);
             txtview.setVisibility(View.GONE);
         }
      }
 });
于 2013-01-16T11:46:42.140 回答
0

此代码段可能有助于显示中间进度:

 Button btnLoad = (Button) findViewById(R.id.btn_load);
     btnLoad.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
             EditText etUrl = (EditText) findViewById(R.id.et_url);
              mWvUrl.loadUrl(etUrl.getText().toString());
              activity.setProgressBarIndeterminateVisibility(true);
        }
    });

     mWvUrl.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                /** This prevents the loading of pages in system browser */
                return false;
            }

            /** Callback method, executed when the page is completely loaded */
            @Override
            public void onPageFinished(WebView view, String url) {
                 super.onPageFinished(view, url);

                 Toast.makeText(getBaseContext(),
                                "Page loaded Completely",
                                Toast.LENGTH_SHORT).show();

                /** Hiding Indeterminate Progress Bar in the title bar*/
                activity.setProgressBarIndeterminateVisibility(false);

            }

        });
于 2013-01-16T11:50:45.163 回答
0

当您使用时,WebChromeClient您可以根据您的目的覆盖onProgressChanged(WebView view, int progress)此方法,这样的事情就可以完成。

yourWebViewObject.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {
            currentActivity.setTitle("Loading...");
            currentActivity.setProgress(progress * 100);

            if(progress == 100)
                currentActivity.setTitle(R.string.app_name);
        }
});

对于示例程序,您可以使用 Android 的 WebView、WebChromeClient 和 WebViewClient 来加载网页并显示进度

于 2013-01-16T11:48:04.613 回答