Flutter开发App的未来及其在各行业的应用潜力分析
688
2022-11-18
webView加载进度条
如图,在进行webview加载网页的同时,在上方加载了一个动态的进度条,当页面加载完毕后,进度条消失。。。
方法:
1,重写webView
public class ProgressWebView extends WebView{ private ProgressBar progressbar; public ProgressWebView(Context context, AttributeSet attrs) { super(context, attrs); progressbar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal); progressbar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 10, 0, 0)); progressbar.setProgressDrawable(context.getResources().getDrawable(R.drawable.progress_bar)); addView(progressbar); // setWebViewClient(new WebViewClient(){}); setWebChromeClient(new WebChromeClient()); setWebViewClient(new MyWebViewClient()); } //浏览器 private class WebChromeClient extends android.webkit.WebChromeClient { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { progressbar.setVisibility(GONE); } else { if (progressbar.getVisibility() == GONE) progressbar.setVisibility(VISIBLE); progressbar.setProgress(newProgress); } super.onProgressChanged(view, newProgress); } } private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { super.onReceivedError(view, request, error); Log.i("TAG","onReceivedError"); } } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { LayoutParams lp = (LayoutParams) progressbar.getLayoutParams(); lp.x = l; lp.y = t; progressbar.setLayoutParams(lp); super.onScrollChanged(l, t, oldl, oldt); }}
2,存在于Drawable中的Xml文件
3,引用webview
4,代码显示
//WebView加载web资源 webview.loadUrl(" //启用支持javascript webview.getSettings().setJavaScriptEnabled(true);
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~