进度条没有停止

时间:2017-03-08 18:45:07

标签: java android

网站加载时看起来像加载。它并没有停止。这是我的代码。

public void cosh2() {

        progressBar3 = (ProgressBar) findViewById(R.id.progressBar3);
        progressBar3.setVisibility(ProgressBar.INVISIBLE);
        progressBar3.setProgress(progress);


        if(progress ==100){
            progressBar3.setVisibility(ProgressBar.GONE);
        }

        webView30 = (WebView) findViewById(R.id.webview30);
        webView30.setWebViewClient(new WebViewClient());
        WebSettings webSettings = webView30.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView30.loadUrl("http://rangamati.gov.bd/");
    }

    public boolean onKeyDown(int keyCode, KeyEvent event){
        if ((keyCode==KeyEvent.KEYCODE_BACK)&&webView30.canGoBack()){
            webView30.goBack();
            return true;
        }

        return super.onKeyDown(keyCode,event);

2 个答案:

答案 0 :(得分:2)

我为我的某个应用做了这个,而且工作得很好

onCreate

 MainActivity.this.progressBar3.setProgress(0);


    final Activity MainActivity = this;
    webView30.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress)   
    {

    MainActivity.this.setValue(progress);
    super.onProgressChanged(view, progress);
    MainActivity.setProgress(progress * 100); 

    if(progress == 100){
    MainActivity.this.progress.setVisibility(View.INVISIBLE);}


    else{
    MainActivity.this.progress.setVisibility(View.VISIBLE);
        }
    }

    });

答案 1 :(得分:0)

你可以理想地使用这种方式在页面加载时你会收到一个回调你可以停止在那里显示pogess吧。

public void cosh2() {

        progressBar3 = (ProgressBar) findViewById(R.id.progressBar3);
        progressBar3.setVisibility(ProgressBar.VISIBLE);
        webView30 = (WebView) findViewById(R.id.webview30);
        webView30.setWebViewClient(new WebViewClient() {
    public void onPageFinished(WebView webview, String url) {
        progressBar3.setVisibility(ProgressBar.GONE);

    }
});
       WebSettings webSettings = webView30.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView30.loadUrl("http://rangamati.gov.bd/");
    }

    public boolean onKeyDown(int keyCode, KeyEvent event){
        if ((keyCode==KeyEvent.KEYCODE_BACK)&&webView30.canGoBack()){
            webView30.goBack();
            return true;
        }

        return super.onKeyDown(keyCode,event);