Remove scroll bar track from ScrollView in Android
Asked Answered
L

6

105

My Android app has a main WebView (HTML loaded from a local resource) which I want to use the entire width of the screen and be able to make (vertically) scrollable. So I've wrapped the WebView in a ScrollView in my layout XML, but no matter what I do I can't seem to be able to remove the scroll bar track from the right side of the scroll view. Even worse, I can't seem to be able to change the background colour of the scroll bar track.

The track takes up about 10dp's or so, which is creating problems for the HTML in the WebView. I'd like the scroll bar to appear on top of the web view (iPhone style, if you know what I mean). Now, you could say "why don't you change your HTML to be 10px thinner?", which is my fallback solution, but I'd much rather not have to.

Here's the relevant snippet of layout XML, you'll see I've tried every android:etc attribute I could find:

<ScrollView 
  android:id="@+id/deal_web_view_holder"
  android:layout_below="@id/clock_bar_holder"
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:fillViewport="false"
  android:fadingEdge="none"
  android:background="#02a7e9"
  android:scrollbars="none"
  android:scrollbarSize="0dp"
  android:paddingRight="0dp"
  android:scrollbarAlwaysDrawVerticalTrack="false"
  android:scrollbarStyle="insideOverlay"
  android:scrollbarTrackVertical="@drawable/scrollbar_track_vertical" >
    <WebView
       android:id="@+id/deal_web_view"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"/>  
</ScrollView>

I'm targeting platform 2.1 / API lvl 7, really just dealing with normal size displays, mdp, hdp and xhdp.

Luben answered 8/6, 2011 at 1:29 Comment(0)
I
509

To remove a scrollbar from a view (and its subclass) via xml:

android:scrollbars="none"

http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars

Ideality answered 20/1, 2012 at 2:55 Comment(3)
This is not what the question poster asked. He said he would like the scrollbar to appear on top of the web view contentKisumu
It works but you will not be able to scroll the screen when keyboard is openBohol
android:scrollbarThumbVertical="@null" Add this on scrollview if you want your screen to scroll when keyboard is open :)Chilon
C
29

try this is your activity onCreate:

ScrollView sView = (ScrollView)findViewById(R.id.deal_web_view_holder);
// Hide the Scollbar
sView.setVerticalScrollBarEnabled(false);
sView.setHorizontalScrollBarEnabled(false);

http://developer.android.com/reference/android/view/View.html#setVerticalScrollBarEnabled%28boolean%29

Charissacharisse answered 8/6, 2011 at 1:34 Comment(1)
Thanks... I'd tried that one already (in code and in the layout.xml), but this approach still interfered with the horizontal size of the WebView within the ScrollView. The best solution was the one provided above, just removing the ScrollView altogether and allowing the WebView to handle the scrolling itself. The root problem was my lack of understanding of how when it was appropriate to use a ScrollView at all; i.e. every view in Android can handle scrolling.Luben
M
18

I'm a little confused why you are putting a WebView into a ScrollView in the first place. A WebView has it's own built-in scrolling system.

Regarding your actual question, if you want the Scrollbar to show up on top, you can use

view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY) or   
android:scrollbarStyle="insideOverlay"
Megilp answered 8/6, 2011 at 1:55 Comment(4)
Yes, you're right about not needing the ScrollView in the first place, I worked that out myself before checking back here. The 'setScrollBarStyle' on the web view worked a treat, thanks!Luben
Not only is it not needed, a ScrollView cannot contain scrollable views, so your WebView would not have scrolled anywayPacificas
Not working. The correct answer is Garzahd's answer.Islamism
the correct answer is below, android:scrollbars="none"Ennui
A
5

Solved my problem by adding this to my ListView:

android:scrollbars="none"
Asinine answered 28/4, 2017 at 20:12 Comment(0)
B
4

These solutions Failed in my case with Relative Layout and If KeyBoard is Open android:scrollbars="none" & android:scrollbarStyle="insideOverlay" also not working.

toolbar is gone, my done button is gone.

not Working

This one is Working for me

myScrollView.setVerticalScrollBarEnabled(false);
Basque answered 18/8, 2017 at 6:47 Comment(0)
B
2

By using below, solved the problem

android:scrollbarThumbVertical="@null"
Backwardation answered 25/10, 2018 at 6:31 Comment(1)
From Review: Hi, please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. ThanksCilurzo

© 2022 - 2024 — McMap. All rights reserved.