Show a progress bar on a child tab until the WebView loads

前端 未结 4 1229
小鲜肉
小鲜肉 2021-01-01 00:05

In an Android app I am using a TabView and one of the tabs shows a WebView. But the page is blank until the web page loads. How would one show a progress bar until the page

4条回答
  •  甜味超标
    2021-01-01 00:46

    I use a ProgressBar for this. With a layout like this:

    
    
    
      
    
      
    
    

    I hide and show the progress indicator using:

     WebView webView = (WebView) findViewById(R.id.WebView);
    
     final ProgressBar progess = (ProgressBar) findViewById(R.id.ProgressBar);
    
      webView.setWebViewClient(new WebViewClient() {
      public void onPageStarted(WebView view, String url, Bitmap favicon) {
        progess.setVisibility(View.VISIBLE);
      }
    
      public void onPageFinished(WebView view, String url) {
        progess.setVisibility(View.GONE);
      }
    }
    

提交回复
热议问题