我正在构建一个 Android WebView 应用程序和我在 WebView 中加载的网站包含引导模式,它显示为登录/注册弹出窗口或选择图像弹出窗口。
但问题是,当模态出现时,滑动刷新正在工作并且我无法向上滚动,因为滑动刷新会自动刷新页面,所以我只想在模式打开时禁用滑动刷新。
在 Chrome 应用程序中,当 Modal 打开或出现时,滑动刷新会自动禁用,所以我想设置为 chrome android 应用程序。
提前致谢
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:id="@+id/relative"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipeRefreshLayout"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="WebViewLayout">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="8dp"
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-2dp"
android:progress="20"
android:visibility="gone"
android:indeterminate="true"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="@color/white" />
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/myWebView"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:nestedScrollingEnabled="true"
android:isScrollContainer="true"
tools:ignore="ObsoleteLayoutParam,RtlHardcoded" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:id="@+id/relativeLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet Connetion, Please Connect To Internet And Try Again. "
android:textSize="30dp"
android:textColor="@color/white"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:layout_marginTop="40dp"
android:id="@+id/txtNoConeection"
android:layout_marginRight="23dp"
android:layout_marginLeft="25dp"
android:gravity="center_horizontal" />
<Button
android:layout_width="140dp"
android:layout_height="65dp"
android:text="Retry"
android:backgroundTint="@color/white"
android:textColor="#620839"
android:layout_below="@+id/txtNoConeection"
android:layout_centerHorizontal="true"
android:layout_marginTop="400dp"
android:textSize="20dp"
android:id="@+id/btnNoConnection"/>
</RelativeLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
在 onCreate
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeColors(Color.rgb(0,72,85), Color.rgb(255,216,96) , Color.rgb(93,7,53) );
swipeRefreshLayout.setOnRefreshListener(() -> {
webView.reload();
if (null != swipeRefreshLayout){
swipeRefreshLayout.setRefreshing(false);
}
});
//Solved WebView SwipeUp Problem
swipeRefreshLayout.getViewTreeObserver().addOnScrollChangedListener(() -> swipeRefreshLayout.setEnabled(webView.getScrollY() == 0));