How to listen for a WebView finishing loading a URL?

前端 未结 17 753
予麋鹿
予麋鹿 2020-11-22 05:40

I have a WebView that is loading a page from the Internet. I want to show a ProgressBar until the loading is complete.

How do I listen for

17条回答
  •  旧巷少年郎
    2020-11-22 06:11

    The renderer will not finish rendering when the OnPageFinshed method is called or the progress reaches 100% so both methods don't guarantee you that the view was completely rendered.

    But you can figure out from OnLoadResource method what has been already rendered and what is still rendering. And this method gets called several times.

            @Override
            public void onLoadResource(WebView view, String url) {
                super.onLoadResource(view, url);
               // Log and see all the urls and know exactly what is being rendered and visible. If you wanna know when the entire page is completely rendered, find the last url from log and check it with if clause and implement your logic there.
                if (url.contains("assets/loginpage/img/ui/forms/")) {
                    // loginpage is rendered and visible now.
                   // your logic here.
    
                }
            }
    

提交回复
热议问题