How to Stop Android webView swipeToRefresh loading progressbar?

帅比萌擦擦* 提交于 2021-02-07 09:19:07

问题


Note: This question was already asked here. which did not get any answer so I decided to repost it with my code.

I want a webView to refresh the current page when a user pulls down the screen from the top which is working fine. The problem is the loading progress bar isn't stopping after the page has been loaded.

Here's the MainActivity.java

// Swipe to Refresh
        SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeToRefresh);
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                myWebView.reload(); // refreshes the WebView
            }
        });
    }
@Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            if (null != swipeLayout && swipeLayout.isRefreshing()) {
                swipeLayout.setRefreshing(false);
            }
        }

I have updated the code but it's still loading.


回答1:


This has fixed the issue:

        final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeToRefresh);
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                myWebView.reload(); // refreshes the WebView

                if (null != swipeLayout) {
                    swipeLayout.setRefreshing(false);
                }
            }
        });



回答2:


Set visibility gone to progressBar inside your seOnRefreshListner and stop refreshing swipeLayout after webview is loaded.

  swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {  
  @Override public void onRefresh() { // Insert your code here
      ProgressBar. SetVisibility(GONE); 
      if(null != swipeLayout) {
           swipeLayout.setRefreshing(false);
      }          
      myWebView.reload(); // refreshes the WebView 
  } });



回答3:


more precisely you try code

if (swipeLayout.isRefreshing()) {
    swipeLayout.setRefreshing(false);
}


来源:https://stackoverflow.com/questions/45324875/how-to-stop-android-webview-swipetorefresh-loading-progressbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!