25

I want to hide a vertical scroll bar in my WebView when I do not scroll the page. As for now, it is displayed always. I create a WebView programmatically, so my question is related to customization of the scroll bar programmatically. Thanks!

Ganapathy C
  • 5,889
  • 5
  • 41
  • 73
lomza
  • 8,884
  • 13
  • 66
  • 84

8 Answers8

59

try this code,

webView.setVerticalScrollBarEnabled(false);
ilango j
  • 5,917
  • 2
  • 26
  • 25
45

No need to change your Java code.
It will work if you put android:scrollbars="none" in your XML.

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none" />
Vadim Kotov
  • 7,766
  • 8
  • 46
  • 61
Vettiyanakan
  • 6,656
  • 3
  • 32
  • 51
16

setScrollbarFadingEnabled() method does exactly what you want. It hides scrollbar when the view isn't scrolling.

webView.setScrollbarFadingEnabled(true);
Sergey Glotov
  • 19,939
  • 11
  • 82
  • 96
12

Set scrollbars to none in the XML for WebView. For reference try this code.

<WebView android:id="@+id/webView"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:scrollbars="none"/> 
Luis Lavieri
  • 3,857
  • 6
  • 38
  • 65
8

This is what you are after:

mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
worked
  • 5,594
  • 5
  • 51
  • 78
2

Try this -

For vertical scrollbar -

webView.setVerticalScrollBarEnabled(false) 

For Horizontal scrollbar -

webView.setHorizontalScrollBarEnabled(false);
Sujeet Kumar
  • 226
  • 1
  • 11
1

Similar to other answers but to get a scrollbar that behaves like the one in ListView, this is the code:

webView.setScrollbarFadingEnabled(true); // Explicitly, however it's a default, I think.
webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
Pijusn
  • 10,635
  • 7
  • 54
  • 75
1

This finally worked for me:

mWebView.setVerticalScrollBarEnabled(false);
the Tin Man
  • 155,156
  • 41
  • 207
  • 295
Ian Mabuka
  • 11
  • 1
  • It helps more if you supply an explanation why this is the preferred solution and explain how it works. We want to educate, not just provide code. – the Tin Man May 24 '20 at 18:41