ANDROID(Java) - 页面上的进度条可见性完成加载不起作用?

时间:2014-08-29 19:08:08

标签: java android xml webview visibility

进度条和webview工作正常,但当页面完成加载时,进度条仍然存在?当我加载页面时,进度条的可见性不会消失/更改为GONE?错误在哪里?

package za.co.test.example;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class KlokTyd extends Activity{

    ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.klok_tyd);

        WebView ourBrow = (WebView) findViewById(R.id.wvBrowser);
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);

        ourBrow.setWebViewClient(new WebViewClient());
        ourBrow.getSettings().setJavaScriptEnabled(true);
        ourBrow.loadUrl("http://example.blogspot.com/");

    }

       public class myWebClient extends WebViewClient 
       {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
        }

       }


}

1 个答案:

答案 0 :(得分:0)

您正在定义一个扩展WebViewClient的类但您​​永远不会使用它。将您自己的班级(myWebViewClient)的实例传递给setWebViewClient()。改变行

ourBrow.setWebViewClient(new WebViewClient());

ourBrow.setWebViewClient(new myWebClient());