Hiding the scroll bar in WebView

2019-01-11 13:24发布

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!

6条回答
叼着烟拽天下
2楼-- · 2019-01-11 13:58

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" />
查看更多
来,给爷笑一个
3楼-- · 2019-01-11 13:58

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);
查看更多
地球回转人心会变
4楼-- · 2019-01-11 14:02

try this code,

webView.setVerticalScrollBarEnabled(false);
查看更多
走好不送
5楼-- · 2019-01-11 14:03

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"/> 
查看更多
劳资没心,怎么记你
6楼-- · 2019-01-11 14:05

This is what you are after:

mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
查看更多
放我归山
7楼-- · 2019-01-11 14:13

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

webView.setScrollbarFadingEnabled(true);
查看更多
登录 后发表回答