Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop INTERNAL scrolling of WebView in Android?

I have a WebView in my application which has HTML content rendered in it and size of HTML content is larger than size of WebView. Due to which content is scrolling inside it when user drags his/her finger on it. I want to stop this INTERNAL scrolling being happening with content.

Heres what I have already tried so far:

WebView view = new WebView(context);  //context is of Activity
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(false);
view.setScrollContainer(false);

and in CSS as:

overflow : hidden !important;

Kindly suggest solutions except Disabling Finger Drag (Hack) for webview because that disturb my other functionality, which is as follows:

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if(motionEvent.getAction() == MotionEvent.ACTION_MOVE)
    {
        return true;
    }
  }
like image 800
Perry Avatar asked Jan 07 '15 12:01

Perry


People also ask

How do I disable scrolling in Webview?

setScrollContainer(false); Don't forget to add the webview. setOnTouchListener(...) code above to disable all scrolling in the webview.

How to disable scrolling of nestedscrollview in android?

setnestedscrollingenabled set it to false.

How do I disable scroll in Webview flutter?

To disable vertical scrolling in flutter webview you can override onVertivalDragUpdate() correspondingly.


1 Answers

Add a container to your webview that wraps all your content and sits just below the body element, like so:

<body id="myBody">
  <div class="container">
    <!-- All your content goes in this new div.container -->
  </div>
</body>

Then, add this CSS to your page:

body {
  height: 100%;
  width: 100%;
  pointer-events: none;
}
div.container {
  overflow: hidden!important;
  height: 100%;
  width: 100%;
}

The problem is that a WebView seems to ignore scrolling on the body despite overflow rules, and since a body expands to meet its contents, it'll always think there is more to scroll to. What this is doing is resetting the body to the size of the WebView, and then using the container to keep the body from expanding beyond the WebView with more content.

Hope that helps.

like image 125
Josh Burgess Avatar answered Oct 08 '22 08:10

Josh Burgess