26

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,989
  • 5
  • 42
  • 75
lomza
  • 9,412
  • 15
  • 70
  • 85

8 Answers8

61

try this code,

webView.setVerticalScrollBarEnabled(false);
ilango j
  • 5,967
  • 2
  • 28
  • 25
48

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
  • 8,084
  • 8
  • 48
  • 62
Vettiyanakan
  • 7,957
  • 6
  • 37
  • 55
16

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

webView.setScrollbarFadingEnabled(true);
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
13

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
  • 4,064
  • 6
  • 39
  • 69
8

This is what you are after:

mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
worked
  • 5,762
  • 5
  • 54
  • 79
2

Try this -

For vertical scrollbar -

webView.setVerticalScrollBarEnabled(false) 

For Horizontal scrollbar -

webView.setHorizontalScrollBarEnabled(false);
Sujeet Kumar
  • 256
  • 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
  • 11,025
  • 7
  • 57
  • 76
1

This finally worked for me:

mWebView.setVerticalScrollBarEnabled(false);
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
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