如何停止Android webView swipeToRefresh加载进度条?

时间:2017-07-26 10:54:48

标签: java android android-layout webview pull-to-refresh

注意:这个问题已经被问到here.没有得到任何答案,所以我决定用我的代码重新发布它。

当用户从顶部向下拉屏幕时,我希望webView刷新当前页面。问题是加载页面后加载进度条没有停止。

这是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);
            }
        }

我已更新代码,但仍在加载。

3 个答案:

答案 0 :(得分:1)

这解决了这个问题:

        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);
                }
            }
        });

答案 1 :(得分:0)

将可见性设置为seOnRefreshListner中的progressBar,并在加载webview后停止刷新swipeLayout。

  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 
  } });

答案 2 :(得分:-1)

更准确地说,你尝试代码

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