0

我正在尝试为 android 创建一个简单的应用程序progress bar。一切正常。但是,这里有两个问题

1)当应用程序启动时,我可以看到进度加载两次。

2)如何在初始页面加载完成后禁用进度条。我不想在每次点击时显示进度条..

这是我的代码

package com.mycom.jquery;
import android.app.Activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class HelloWebView extends Activity {

WebView webview;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
            Window.PROGRESS_VISIBILITY_ON);

    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {

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

    });
    final Activity activity = this;

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMessage("Loading...Jquery.com");
    progressDialog.setCancelable(true);

    webview.loadUrl("http://www.jquery.com");

    // WebChromeClient give progress etc info
    webview.setWebChromeClient(new WebChromeClient() {

        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();
        }
    });

}

}
4

3 回答 3

2

试着打电话

progressDialog.show();

在外面

onProgressChanged(WebView view, int progress)
于 2012-03-26T05:58:43.813 回答
1

当进度变为 100 时设置一个标志,然后在您的实现中true立即返回该标志。onProgressChanged

于 2012-03-26T05:47:42.980 回答
0

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

尝试删除它。从你的代码。

于 2012-03-26T05:57:57.937 回答