1

我无法将 webview 应用程序中的进度条更改为 circle.the 应用程序在启动时崩溃..这是代码

@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
        WebSettings websettings = webview.getSettings();
        websettings.setJavaScriptEnabled(true);

        getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Request progress circle
        setProgressBarIndeterminateVisibility(true); // Show progress circle

    //  webview.setWebViewClient(new WebViewClient());

        final Activity activity = this;

        webview.setWebChromeClient(new WebChromeClient(){

                public void onProgressChanged(WebView view, int progress) {
                    activity.setTitle("Loading...");
                    activity.setProgress(progress * 100);
                    if(progress == 100)
                        setProgressBarIndeterminateVisibility(false); // Hide progress circle when page loaded
                    activity.setTitle("Title");
                }
            });
        if (savedInstanceState == null)
        {
            webview.loadUrl("http://www.proboards.com/");
        }


    }

有人可以帮忙吗?

4

2 回答 2

0

我在您的代码中看到了一些缺陷。

As far as I know, the ProgressBar value should be less than or equal to 100.
You are setting it to (progress * 100)

Also, once progress == 100, you hide the progress bar,
this will take place when progress = 1. Then you hide the progress bar.

希望这可以帮助。

    private ProgressBar mProgress;
    private int mProgressStatus = 0;

    mProgress = (ProgressBar) findViewById(R.id.progress_bar);

    // Start lengthy operation in a background thread
         new Thread(new Runnable() {
             public void run() {
                 while (mProgressStatus < 100) {
                     mProgressStatus = doWork();

                     // Update the progress bar
                     mHandler.post(new Runnable() {
                         public void run() {
                             mProgress.setProgress(mProgressStatus);
                         }
                     });
                 }
             }
         }).start();
于 2013-09-03T16:45:28.333 回答
0

您的应用程序崩溃,因为这一行:

Activity.getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

需要在调用之前调用 Activity.setContentView(...);

您之前正在调用 setContentView(...),这就是您的应用崩溃的原因。

这就是为什么,来自 Android-Developer 页面:

http://developer.android.com/reference/android/view/Window.html#requestFeature%28int%29

于 2013-09-03T16:53:30.307 回答