Android Webview 加载对话框未被关闭 [英] Android Webview loading dialog not being dismissed

查看:73
本文介绍了Android Webview 加载对话框未被关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码

class CustomWebViewClient extends WebViewClient {
    Context context;
    ProgressDialog pd = null;


    public CustomWebViewClient (Context c){
        context = c;
    }

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



    public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
        pd = ProgressDialog.show(context, "", "pageload. Please wait...", true);


        view.loadUrl(url);  

        return true;
    } 

}

当我单击 WebView 中的链接时,会出现对话框并开始加载页面,但是当页面加载完成后,该对话框仍在屏幕上.显然代码很简单,但我无法弄清楚.另外,我想我应该补充一点,被点击的链接有一些重定向,但我不确定这是否与此处的原因有关.

When I click a link in the WebView, the dialog appears and the page begins to load, however when the page is finished loading, the dialog is still on the screen. Obviously the code is simple enough, but I cant figure this out. Also, I guess I should add that the links being clicked have a few redirects, but I am not sure if that is related to the cause here.

我怎样才能做到这一点?

How can I do this right?

推荐答案

Steven &Sander,尝试关闭 Handler 中的进度对话框

Steven & Sander, try dismissing the progress dialog in a Handler

像这样:

  class pdHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
      if(pd != null)
      {
      pd.dismiss();
      pd = null;
      }
    }

然后在 onPageFinished 中调用您的处理程序:

Then call your handler in onPageFinished:

 public void onPageFinshed(WebView view, String url){
        pdHandler.sendEmptyMessage(0);
    }

&大功告成!

这篇关于Android Webview 加载对话框未被关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆