How to show loading image or progress bar on WebView

前端 未结 3 1685
陌清茗
陌清茗 2021-01-29 02:29

I have a webView in android that loads a particular site, i want to display a loading icon or progress bar on clicking any of the links inside the webView.

    w         


        
3条回答
  •  花落未央
    2021-01-29 03:17

    First, you have to figure out when the click happens :

    webView.setWebViewClient(new WebViewClient() { 
                public boolean shouldOverrideUrlLoading(WebView view, String url){
                    webView.loadUrl(url); 
                    // Here the String url hold 'Clicked URL' 
                    return false; 
                } 
            });
    

    Then, you have to put the Progressbar in a FrameLayout with your WebView.

    
    
    
    
    
    
     
    

    So, when the click happens, you can show your progressbar inside your Activity.

    webView.setWebViewClient(new WebViewClient() { 
                public boolean shouldOverrideUrlLoading(WebView view, String url){
                if (url.equals("your_url"){
                progressbar.setVisibility(View.VISIBLE);
                } 
                    return false; 
                } 
            });
    

提交回复
热议问题