1.在layout 中间写一个隐藏的
loadinggetActivityView().getProgressWebView().setWebChromeClient(newWebChromeClient(){
@Override
public voidonProgressChanged(WebView view,intnewProgress) {
if(newProgress ==100) {
getActivityView().getLoading_view().setVisibility(View.GONE);
}else{
if(getActivityView().getLoading_view().getVisibility() == View.GONE)
getActivityView().getLoading_view().setVisibility(View.VISIBLE);
}
super.onProgressChanged(view, newProgress);
}
});
2.顶部进度条
public classProgressWebViewextendsWebView {
privateProgressBarmProgressBar;
publicProgressWebView(Context context, AttributeSet attrs) {
super(context, attrs);
mProgressBar=newProgressBar(context,null,
android.R.attr.progressBarStyleHorizontal);
LinearLayout.LayoutParams layoutParams =newLinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,8);
mProgressBar.setLayoutParams(layoutParams);
Drawable drawable = context.getResources().getDrawable(
R.drawable.web_progress_bar_states);
mProgressBar.setProgressDrawable(drawable);
addView(mProgressBar);
setWebChromeClient(newWebChromeClient());
}
public classWebChromeClientextendsandroid.webkit.WebChromeClient {
@Override
public voidonProgressChanged(WebView view,intnewProgress) {
if(newProgress ==100) {
mProgressBar.setVisibility(GONE);
}else{
if(mProgressBar.getVisibility() ==GONE)
mProgressBar.setVisibility(VISIBLE);
mProgressBar.setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
}
}
@Override
protected voidonScrollChanged(intl,intt,intoldl,intoldt) {
LayoutParams lp = (LayoutParams)mProgressBar.getLayoutParams();
lp.x= l;
lp.y= t;
mProgressBar.setLayoutParams(lp);
super.onScrollChanged(l, t, oldl, oldt);
}
}
android:startColor="@android:color/transparent"
android:centerColor="@android:color/transparent"
android:endColor="@android:color/transparent"
/>
android:startColor="#234"
android:centerColor="#234"
android:endColor="#a24"
/>
android:startColor="#33000001"
android:centerColor="#40000000"
android:endColor="@color/common_title_color"
/>