我在 ViewPager(v4 支持)中有一个 webview,我想在应用加载时放置一个进度条。这是我到目前为止所拥有的,但它不起作用。基本上我让它指向我的 WebVIew 布局文件中的进度条,但它没有加载任何东西......?
private class MyPagerAdapter extends PagerAdapter {
public int getCount() {
return 3;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.web_view;
break;
case 1:
resId = R.layout.media;
break;
case 2:
resId = R.layout.youtube;
break;
}
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
web = (WebView) findViewById(R.id.web_view);
final ProgressBar bar = (ProgressBar) findViewById(R.id.loading);
web.loadUrl(url);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient () {
@Override
public void onLoadResource(WebView view, String url) {
// TODO Auto-generated method stub
web.loadUrl("javascript:var element = document.getElementById('social-tabs'); element.parentElement.removeChild(element);");
web.loadUrl("javascript:var element = document.getElementById('omc-top-banner'); element.parentElement.removeChild(element);");
web.loadUrl("javascript:var element = document.getElementById('simplereach- slide-element'); element.parentElement.removeChild(element);");
}
@Override
public void onPageStarted(WebView view, String url,
Bitmap favicon) {
// TODO Auto-generated method stub
bar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
bar.setVisibility(View.GONE);
}
});
return view;
}