61

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?

Felix
  • 84,032
  • 41
  • 145
  • 163
  • 1
    An obvious (but bad) solution is to wrap the `WebView` in a `ScrollView` and set `scrollbarStyle="insideOverlay"` on that. – Felix Oct 22 '10 at 16:31
  • Also, my current solution is `android:scrollbars="none"` which permanently hides the scrollbars (and also the white area). This is not optimal, however. – Felix Oct 22 '10 at 16:43

2 Answers2

116

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.

Yaks
  • 1,175
  • 1
  • 9
  • 6
  • 2
    While we're on the topic, the same is true of the background color for WebViews. You have to use webView.setBackgroundColor(...) or it won't actually apply. – Yaks Jan 29 '11 at 22:27
2
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.

Tim Cooper
  • 144,163
  • 35
  • 302
  • 261
xujiyong
  • 21
  • 2