1

私のアプリには webview があり、web の読み込みが完了するまで、表示の読み込み用の進行状況ダイアログを追加します。私はグーグルで検索し、良い解決策を得ました

wv.setWebChromeClient(new MyWebChromeClient());
wv.setWebViewClient(new MyWebViewClient());
wv.loadUrl("http://www.google.com"); 

     private class MyWebViewClient extends WebViewClient {
        @Override
         public boolean shouldOverrideUrlLoading(WebView view, String url) 
        {
            view.loadUrl(url);
            return true;
        }

        @Override
     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            alertdialog.setTitle("Error");
            alertdialog.setMessage(description);
            alertdialog.setButton("OK", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
                 //return;
                finish();
             }
         });
            alertdialog.show();
     }
    }


    private class MyWebChromeClient extends WebChromeClient {

        @Override
        public void onProgressChanged(WebView view, int progress) {
            progressDialog.show();
            progressDialog.setProgress(0);
            activity.setProgress(progress * 1000);

            progressDialog.incrementProgressBy(progress);

            if(progress == 100 && progressDialog.isShowing())
                progressDialog.dismiss();
        }

    }

しかし、私の問題は、progressdialogを起動した後に一度だけ表示する方法です.今、写真のような例をクリックすると(google.comで)進行状況ダイアログが再び表示されるからです.

4

4 に答える 4

4
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
            setContentView(R.layout.info);

            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgressDialog.setMessage("Please wait...");
            mProgressDialog.setCancelable(false);
            mProgressDialog.setMax(100);
            mProgressDialog.show();

            WebView webView = (WebView) findViewById(R.id.webview);
            webView.setVisibility(View.VISIBLE);
            webView.getSettings().setJavaScriptEnabled(true);

            webView.setWebChromeClient(new WebChromeClient() {
                public void onProgressChanged(WebView view, final int progress)
                {
                    activity.setTitle("Loading...");
                    activity.setProgress(progress * 100);
                    mProgressDialog.setProgress(progress );




                    if(progress == 100)
                    {
                        activity.setTitle(R.string.app_name);
                        mProgressDialog.dismiss();
                    }

                }
            });

            webView.setWebViewClient(new WebViewClient() {
                @Override
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                {
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url)
                {
                    view.loadUrl(url);
                    return true;
                }
            });

            webView.loadUrl("http://www.google.com");
于 2012-07-31T05:26:03.517 に答える
1

progressbarページが のときに webview に表示されるコードの下を確認してくださいloading

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.newsdisplay);
    getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 


    newswebview = (WebView) findViewById(R.id.news_webView);
    newswebview.setWebViewClient(new WebViewClient());
    WebSettings webSettings = newswebview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    newswebview.getSettings().setSupportZoom(true);       //Zoom Control on web (You don't need this 
     //if ROM supports Multi-Touch      
    newswebview.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM


    newswebview.loadUrl(url);


    final Activity MyActivity = this;

newswebview.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) 
       {

        //Make the bar disappear after URL is loaded, and changes string to Loading...
        MyActivity.setTitle("  Loading...");
        MyActivity.setProgress(progress * 100); //Make the bar disappear after URL is loaded

        // Return the app name after finish loading
           if(progress == 100)
              MyActivity.setTitle(R.string.app_name);

    }
});

}


 @Override  
    public boolean onKeyDown(int keyCode, KeyEvent event)   
    {  
        if ((keyCode == KeyEvent.KEYCODE_BACK) && newswebview.canGoBack()) {  
            newswebview.goBack();  
            return true;  
        }  
        return super.onKeyDown(keyCode, event);  
    }  

}
于 2012-07-31T04:44:10.683 に答える
1

以下のコードを試すことができます

    view = (WebView) findViewById(R.id.WebView01);
    view.setBackgroundColor(0);  // set the background transparent 

    progressDialog = ProgressDialog.show(view.getContext(), "Loading...", "Loading...");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER    );

    view.setWebChromeClient(new MyWebChromeClient());
    view.getSettings().setJavaScriptEnabled(true);
    view.setWebViewClient(new MyWebViewClient());
    view.loadUrl("http://www.xxx.com/web/apps/jots.do");

そして、クラスを作成します

private class MyWebViewClient extends WebViewClient {
    @Override
     public boolean shouldOverrideUrlLoading(WebView view, String url)      
    {
        view.loadUrl(url);
        return true;
    }
}

private class MyWebChromeClient extends WebChromeClient {

    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        if(progressDialog!=null){
            if ( newProgress >=80 ) {
                progressDialog.dismiss();
            } else {
                progressDialog.setMessage(newProgress + " % loaded");
            }
        }
        super.onProgressChanged(view, newProgress);
    }
}
于 2012-07-31T05:14:19.887 に答える
1

//このコードを使用して、webview で進行状況を表示します

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
            setContentView(R.layout.info);
            WebView webView = (WebView) findViewById(R.id.webview);
            webView.setVisibility(View.VISIBLE);
            webView.getSettings().setJavaScriptEnabled(true);

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

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

            webView.setWebViewClient(new WebViewClient() {
                @Override
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                {
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url)
                {
                    view.loadUrl(url);
                    return true;
                }
            });

            webView.loadUrl("http://www.google.com");
于 2012-07-31T04:46:11.757 に答える