How to show loading image or progress bar on WebView

前端 未结 3 1652
陌清茗
陌清茗 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:07

     webViewClient = (WebView) findViewById(R.id.contentContainer);
    
        WebSettings webSettings = webViewClient.getSettings();
    
        webSettings.setJavaScriptEnabled(true);
    
        webViewClient.setWebViewClient(new WebViewClient(){
    
         public void onProgressChanged(WebView view, int progress) {
                 activity.setTitle("Loading...");
                 activity.setProgress(progress * 100);
                    if(progress == 100)
                       activity.setTitle("Your Title");
                 });
    
        webViewClient.loadUrl("URL");
    
    Following Link May help you as well : http://www.firstdroid.com/2010/08/04/adding-progress-bar-on-webview-android-tutorials/
    

提交回复
热议问题