SwipeRefreshLayout和处理webview中的外部链接(手动类)在android webview中无法协同工作
我在android中使用webview,我在webview中实现了拉刷新。我还创建了一个类来处理网站内部的外部链接,只打开应用程序内部的链接,但问题是重新加载程序一直这样加载 webview片段的xml文件SwipeRefreshLayout和处理webview中的外部链接(手动类)在android webview中无法协同工作,android,android-studio,android-fragments,webview,swiperefreshlayout,Android,Android Studio,Android Fragments,Webview,Swiperefreshlayout,我在android中使用webview,我在webview中实现了拉刷新。我还创建了一个类来处理网站内部的外部链接,只打开应用程序内部的链接,但问题是重新加载程序一直这样加载 webview片段的xml文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:
<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>
您好,实际上您做错了,因为您在这里设置web view client tow time意味着它将覆盖第一个时间,所以请仅设置第一个时间,并将逻辑放入该onPageFinished中,它将工作。参考下面的答案
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());