【问题标题】:How to Disable Swipe Refresh when Bootstrap Modal Appears in Android WebView?Android WebView中出现Bootstrap Modal时如何禁用滑动刷新?
【发布时间】:2020-12-25 21:41:49
【问题描述】:

我正在构建一个 Android WebView 应用程序和我在 WebView 中加载的网站包含 Bootstrap 模式,它显示为登录/注册弹出窗口或选择图像弹出窗口。

但问题是,当出现模式时,滑动刷新正在工作,我无法向上滚动,因为滑动刷新会自动刷新页面,所以我想仅在模式打开时禁用滑动刷新。

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

【问题讨论】:

    标签: android-webview bootstrap-modal swiperefreshlayout android-overscoll


    【解决方案1】:

    它已经很老了,但由于它出现在谷歌搜索中,可能会对某些人有所帮助...... 我用一种奇怪的方法解决了它。刚刚在我的网站上添加了一些 js。不使用引导程序,但有什么原因它不起作用? 当我打开 div 时:

     document.body.style.overflowY = "hidden";
     document.body.style.minHeight = "calc(100vh + 1px)";
     window.scrollBy(0, 1);
    

    当我关闭它时:

    document.body.style.overflowY = "scroll";
    document.body.style.minHeight = "0px";
    window.scrollBy(0, -1);
    

    如果您找到了更好的解决方案,我也想听听... 我真的不明白为什么它还没有修复。 chrome处理得很好但是webview还是这样...

    首先我尝试使用

    document.body.style.overscrollBehavior = "none";
    

    但是在webview中没有效果...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      相关资源
      最近更新 更多