SwipeRefreshLayout和处理webview(手动类)中的外部链接不能在android webview中一起工作

时间:2018-06-01 03:24:47

标签: android android-studio android-fragments webview swiperefreshlayout

我在android中使用webview我已经在webview中实现了pull to refresh。此外,我已经创建了一个类来处理网站内部的外部链接,只打开应用程序内的链接,但问题是重新加载器继续像这样加载

enter image description here

webview片段的xml文件

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <WebView
            android:id="@+id/Zomato"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            />
    </android.support.v4.widget.SwipeRefreshLayout>

</RelativeLayout>

Desc.java中的SwipeLayout

     SwipeRefreshLayout swipe;
     static WebView webView;
      @Override
      public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

     webView=view.findViewById(R.id.Zomato);

    swipe=view.findViewById(R.id.swipe2);
}
    swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                String url = "https://www.zomato.com/";
                webView.setWebViewClient(new WebViewClient() {
                    @Override
                    public void onPageFinished(WebView view, String url) {
                        swipe.setRefreshing(false);
                    }
                });
             }



webView.setWebViewClient(new Fragment2.GeoWebViewClient());

1 个答案:

答案 0 :(得分:1)

嗨其实你做错了,因为你在这里设置网页视图客户端拖曳时间意味着它将覆盖第一个所以请只设置第一次并将逻辑放在onPageFinished它将工作。 Referer吼叫回答

https://stackoverflow.com/a/6720004/3894930