带进度对话框的 webview android

发布于 2025-01-08 00:07:47 字数 2341 浏览 0 评论 0原文

我正在尝试为带有进度栏的android制作一个webview应用程序,我尝试了很多这里的例子,但没有一个起作用..我的问题是在框架页面或带有facebook点赞或评论插件的页面上,进度对话框永远不会停止..这是我的代码..请测试它并告诉我出了什么问题。

private WebView webview;
private ProgressDialog progressDialog;
boolean loadingFinished = true;
boolean redirect = false;
int nr = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    webview = (WebView) findViewById(R.string.webview);

    final Activity activity = this;

    webview.getSettings().setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (!loadingFinished) {
                redirect = true;
             }

            loadingFinished = false;
            webview.loadUrl(url);

            return true;

        }

        public void onLoadResource(WebView view, String url) {
            if (progressDialog == null) {
                progressDialog = new ProgressDialog(activity);
                progressDialog.setTitle("PitziWorld");
                progressDialog.setMessage(progressDialog.toString());
                progressDialog.setCancelable(isFinishing());
                progressDialog.show();

            }
            loadingFinished = false;
        }
        public void onPageFinished(WebView view, String url) {

            if(!redirect){
                loadingFinished = true;
             }

             if(loadingFinished && !redirect){
                 if (progressDialog.isShowing() || progressDialog!=null) {
                     progressDialog.hide();
                     progressDialog = null;
                 }
             } else{
                redirect = false; 
             }




        }
    }); 
    webview.loadUrl("http://www.pitziworld.ro");

}
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        WebView webView = (WebView) findViewById(R.string.webview);
        //Verifica daca tasta apasata a fost back si daca exista istoric
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        // Daca nu a fost tasta back sau nu este istoric, returnam valoare buton

        `

im trying to make an webview application for android with progress bar, i tried a lot of examples from here but none was working .. my problem is that on a frame page or a page with facebook likes or comment plugin the progressdialog never stoped .. here is my code.. please test it and tell me what is wrong.

private WebView webview;
private ProgressDialog progressDialog;
boolean loadingFinished = true;
boolean redirect = false;
int nr = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    webview = (WebView) findViewById(R.string.webview);

    final Activity activity = this;

    webview.getSettings().setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (!loadingFinished) {
                redirect = true;
             }

            loadingFinished = false;
            webview.loadUrl(url);

            return true;

        }

        public void onLoadResource(WebView view, String url) {
            if (progressDialog == null) {
                progressDialog = new ProgressDialog(activity);
                progressDialog.setTitle("PitziWorld");
                progressDialog.setMessage(progressDialog.toString());
                progressDialog.setCancelable(isFinishing());
                progressDialog.show();

            }
            loadingFinished = false;
        }
        public void onPageFinished(WebView view, String url) {

            if(!redirect){
                loadingFinished = true;
             }

             if(loadingFinished && !redirect){
                 if (progressDialog.isShowing() || progressDialog!=null) {
                     progressDialog.hide();
                     progressDialog = null;
                 }
             } else{
                redirect = false; 
             }




        }
    }); 
    webview.loadUrl("http://www.pitziworld.ro");

}
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        WebView webView = (WebView) findViewById(R.string.webview);
        //Verifica daca tasta apasata a fost back si daca exista istoric
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        // Daca nu a fost tasta back sau nu este istoric, returnam valoare buton

        `

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

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

发布评论

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

评论(1

权谋诡计 2025-01-15 00:07:48

这就是您正在寻找的!

         public void onPageStarted(WebView view, String url, Bitmap favicon) {
           mProgress.show();
       }

在每个页面加载进度条
就是这样!

this is what you are looking for!

         public void onPageStarted(WebView view, String url, Bitmap favicon) {
           mProgress.show();
       }

to load progress bar in every page
this is it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文