how to show progress bar on webview?

后端 未结 5 1658
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 00:38

I am trying to open a webpage in my application using WebView. When I open webpage it shows me blank screen for a while and then open that page in browser insid

5条回答
  •  Happy的楠姐
    2020-12-14 01:19

    You need to do something like this:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_PROGRESS);
        this.setProgressBarVisibility(true);
    }
    

    And then

    final Activity activity = this;
    mWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            activity.setProgress(progress * 100);
        }
    });
    

    Update
    I know it is a bit too late but I have little side note: you shouldn't use setWebViewClient() twice. Second call cancels the first call so you wouldn't get error handling.

提交回复
热议问题