Android WebView 与 ProgressDialog。我该如何杀死它?

发布于 2024-10-31 04:33:43 字数 1458 浏览 1 评论 0原文

我已经尝试了我所知道的一切方法来杀死它。我想要它做的是加载网页然后终止 ProgressDialog。怎么办?

package com.calebfultz.package;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;

public class Lists extends Activity {
    private WebView webView;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web);
        ProgressDialog pd = ProgressDialog.show(Lists.this, "", 
                "Loading. Please wait...", true);
        // Create reference to UI elements
        webView  = (WebView) findViewById(R.id.web_engine);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://cfultz.tumblr.com");


        // workaround so that the default browser doesn't take over
        webView.setWebViewClient(new MyWebViewClient()

        );

    }


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

I've tried everything I know how to do to kill it. What I want it to do is load the webpage and then kill the ProgressDialog. How do?

package com.calebfultz.package;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;

public class Lists extends Activity {
    private WebView webView;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web);
        ProgressDialog pd = ProgressDialog.show(Lists.this, "", 
                "Loading. Please wait...", true);
        // Create reference to UI elements
        webView  = (WebView) findViewById(R.id.web_engine);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://cfultz.tumblr.com");


        // workaround so that the default browser doesn't take over
        webView.setWebViewClient(new MyWebViewClient()

        );

    }


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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蝶舞 2024-11-07 04:33:43

您可能希望将 ProgressDialog 变量作为 Lists 类的成员变量,并在 shouldOverrideUrlLoading 方法中添加以下行

pd.dismiss();

You may want to make your ProgressDialog variable as a member variable of the Lists class and in your shouldOverrideUrlLoading method, add the line

pd.dismiss();
久伴你 2024-11-07 04:33:43
public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // Show your progress dialog here

           prDialog = ProgressDialog.show(this, "", "Loading, please wait...", true);

       super.onPageStarted(view, url, favicon);

    }

public void onPageFinished(WebView view, String url) {

          //Finish your progress dialog here


        if (prDialog.isShowing() || prDialog != null) {
            prDialog.dismiss();
        }

        super.onPageFinished(view, url);

    }
public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // Show your progress dialog here

           prDialog = ProgressDialog.show(this, "", "Loading, please wait...", true);

       super.onPageStarted(view, url, favicon);

    }

public void onPageFinished(WebView view, String url) {

          //Finish your progress dialog here


        if (prDialog.isShowing() || prDialog != null) {
            prDialog.dismiss();
        }

        super.onPageFinished(view, url);

    }
为你鎻心 2024-11-07 04:33:43

我认为您可以重写 MyWebViewClient 中的 onPageFinished 函数:您可以关闭此函数中的 ProgressDialog 。或者您可以重写 MyWebChromeClient(extends WebChromeClient) 中的 onProgressChanged:当进度为 100 时,您可以关闭 ProgressDialog。

I think you can override the onPageFinished function in MyWebViewClient: you can dismiss the ProgressDialog in this function. Or you can override the onProgressChanged in MyWebChromeClient(extends WebChromeClient): when the progress is 100, you can dismiss the ProgressDialog.

挽袖吟 2024-11-07 04:33:43

请查看这段代码:

// the init state of progress dialog
mProgress = ProgressDialog.show(this, "Loading", "Please wait for a moment...");               
// add a WebViewClient for WebView, which actually handles loading data from web
                mWebView.setWebViewClient(new WebViewClient() {
                    // load url
               public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                    return true;
                    }

                    // when finish loading page
                    public void onPageFinished(WebView view, String url) {
                        if(mProgress.isShowing()) {
                            mProgress.dismiss();
                    }
                    }
                });

它对我来说工作得很好......享受吧。

Please see this code:

// the init state of progress dialog
mProgress = ProgressDialog.show(this, "Loading", "Please wait for a moment...");               
// add a WebViewClient for WebView, which actually handles loading data from web
                mWebView.setWebViewClient(new WebViewClient() {
                    // load url
               public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                    return true;
                    }

                    // when finish loading page
                    public void onPageFinished(WebView view, String url) {
                        if(mProgress.isShowing()) {
                            mProgress.dismiss();
                    }
                    }
                });

it is working fine for me.........enjoy.

半﹌身腐败 2024-11-07 04:33:43
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);

        //start loading animation
            //loading is a ProgressBar type
        this.loading.setVisibility(0);
        view.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
               if(progress >= 100) {
                   this.loading.setVisibility(8);
               } 
            }
        });
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);

        //start loading animation
            //loading is a ProgressBar type
        this.loading.setVisibility(0);
        view.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
               if(progress >= 100) {
                   this.loading.setVisibility(8);
               } 
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文