进度条和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);
}
}
}
答案 0 :(得分:0)
您正在定义一个扩展WebViewClient
的类但您永远不会使用它。将您自己的班级(myWebViewClient
)的实例传递给setWebViewClient()
。改变行
ourBrow.setWebViewClient(new WebViewClient());
到
ourBrow.setWebViewClient(new myWebClient());