Android WebView leaves space for scrollbar

AndroidAndroid Webview

Android Problem Overview


In my WebView, I have some block elements that have a background color (different than white). However, the background color does not go all the way across the sky.. um, screen. Instead, it leaves a small white strip to the right, for where the scrollbar would go. Now, I want the scrollbars to appear only when scrolling (and fade away once the user has finished scrolling). I tried:

android:fadingEdge="vertical|horizontal"
android:fadeScrollbars="true"
android:scrollbarStyle="insideOverlay" (and all other options)

Also, my HTML contains the following in <head>:

<meta name="viewport" content="target-densitydpi=device-dpi" />

So that it doesn't allow zooming and doesn't zoom out by default.

However, I can't figure out how to get rid of the white strip. Any ideas?

Android Solutions


Solution 1 - Android

Battled this one as well. Found the answer here.

Looks like you were dead on with android:scrollbarStyle="insideOverlay", except that because of some bug it doesn't function right when defined in XML. It works right if you use:

webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

Annoying.

Solution 2 - Android

public void setVerticalScrollbarOverlay (boolean overlay)

Since: API Level 1
Specify whether the vertical scrollbar has overlay style.
Parameters
overlay TRUE if vertical scrollbar should have overlay style.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFelixView Question on Stackoverflow
Solution 1 - AndroidYaksView Answer on Stackoverflow
Solution 2 - AndroidxujiyongView Answer on Stackoverflow