【问题标题】:Android: ProgressDialog does not animate when first calledAndroid:ProgressDialog 在第一次调用时没有动画
【发布时间】:2014-02-07 10:34:48
【问题描述】:

我有下面的 loadWebView 方法...

private void loadWebView() {
    final WebView myWebView = (WebView) findViewById(R.id.webView);

    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setGeolocationEnabled(true);
    myWebView.setBackgroundColor(0x00000000);
    myWebView.setVisibility(View.VISIBLE);

    final ProgressDialog pd = ProgressDialog.show(this, "", "Connecting...", true);
    myWebView.loadUrl(_Host);

    myWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast toast = Toast.makeText(view.getContext(), "Could not connect.", Toast.LENGTH_LONG);
            toast.show();
            initSettings();
        }
        @Override
        public void onReceivedHttpAuthRequest(WebView view,
                                              HttpAuthHandler handler,
                                              String host,
                                              String realm) {
            handler.proceed(_Username, _Password);
        }
        //@Override
        public void onReceivedSslError(WebView view,
                                       SslErrorHandler handler,
                                       SslError error) {
            handler.proceed();
        }
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon)
        {
            pd.show();
        }
        @Override
        public void onPageFinished(WebView view, String url)
        {
            pd.dismiss();
        }
    });
}

第一次从手机(galaxy nexus)中的主要活动调用时,进度对话框不会动画,但在平板电脑上会。 同样在 nexus 中,当冲浪开始时,它的动画就可以了。

有什么想法吗?其他一切正常!

编辑(已解决) 好的,我找到了解决方案。在 initSettings 方法中,我被称为具有这些属性的 WebView...

WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.setVisibility(View.INVISIBLE);
myWebView.loadUrl = "about:blank";

我将它移到 onReceivedError 上,现在一切正常!

    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        view.setVisibility(View.INVISIBLE);
        view.loadUrl("about:blank");
        Toast toast = Toast.makeText(view.getContext(), "Could not connect.", Toast.LENGTH_LONG);
        toast.show();
        initSettings();
    }

【问题讨论】:

    标签: android webview progressdialog


    【解决方案1】:

    您应该在配置完 WebViewClient 后调用 loadUrl,否则您可能根本不会使用 webviewclient:

     myWebView.setWebViewClient(new WebViewClient() { ..}
     myWebView.loadUrl(_Host);
    

    是的,行为是不可预测的!如果您使用错误的顺序,它可能会起作用,也可能不会。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      相关资源
      最近更新 更多