我正在创建一个Android webview应用程序。我面临着进度条的问题。进度条完全实现并持续旋转。但即使在页面完全加载后它也不会停止旋转。我该怎么办?
主要活动布局::::
<ProgressBar android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
mainActivity.java :::
public class MainActivity extends ActionBarActivity {
WebView web;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.webView1);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setBuiltInZoomControls(true);
web.loadUrl("http://google.com");
web.setWebViewClient(new WebViewClient()); }
public class webclient 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);
}
}
错误在哪里?请帮助我即时通讯也有问题。 here
答案 0 :(得分:1)
您已创建自定义WebViewClient类,但您尚未使用它。
更改web.setWebViewClient(new WebViewClient());
到web.setWebViewClient(new webclient());
答案 1 :(得分:1)
更改这两种方法。
@覆盖 public void onPageStarted(WebView视图,String url,Bitmap favicon){
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
progressBar.dismiss();
}
@覆盖 public void onPageFinished(WebView视图,String url){
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
更改web.setWebViewClient(new WebViewClient());
到web.setWebViewClient(new webclient());