Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android::Webview removes scrollbar for a DIV

I made a small webpage with a scrollable div. When I load it in a browser, it works fine. But when I load it in a webview inside Android, it doesn't let me scroll the div. Is there a workaround for this or do I have to use a different design? I am talking about websites like this.

like image 785
Legend Avatar asked May 23 '10 23:05

Legend


People also ask

How do I get a scrollbar in a div?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

How to restrict overflow in CSS?

In order for overflow to have an effect, the block-level container must have either a set height ( height or max-height ) or white-space set to nowrap . Setting one axis to visible (the default) while setting the other to a different value results in visible behaving as auto .

How do I disable scrolling in Webview?

setScrollContainer(false); Don't forget to add the webview. setOnTouchListener(...) code above to disable all scrolling in the webview.

Which property can be used to set an element to show a scroll bar when the text overflows?

The overflow-x CSS property sets what shows when content overflows a block-level element's left and right edges. This may be nothing, a scroll bar, or the overflow content.


2 Answers

Unfortunely, scrollable div's just aren't supported on most current mobile Webkit browsers. A great alternative to native support is the iScroll Javascript library, which can simulate real scrolling:

http://cubiq.org/iscroll

Copy/pasted from the project description on that page:

The overflow:scroll for mobile webkit. Project started because webkit for iPhone does not provide a native way to scroll content inside a fixed size (width/height) div. So basically it was impossible to have a fixed header/footer and a scrolling central area. Until now.

Version 3.3 and later support Android >= 1.5.

like image 194
David Snopek Avatar answered Sep 22 '22 17:09

David Snopek


You can use pseudo elements of webkit to customize the scroll-bar style.

Try this:

::-webkit-scrollbar {
    width: 12px;
}     

::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
    -webkit-border-radius: 10px;
    border-radius: 10px;
}     

::-webkit-scrollbar-thumb {
    -webkit-border-radius: 10px;
    border-radius: 10px;
    background: rgba(255,0,0,0.8); 
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
}

::-webkit-scrollbar-thumb:window-inactive {
    background: rgba(255,0,0,0.4); 
}
like image 29
Verdigrass Avatar answered Sep 18 '22 17:09

Verdigrass