52

I'm wondering if it's possible to change the color of the ScrollView.

I'm not referring to the background color or the edges.
I attached a print screen of the bar I'm referring. For me, it's kind of transparnt.

Here's how I defined it in the xml:

<ScrollView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:fadeScrollbars="false"
    android:layout_toLeftOf="@+id/personalscores_BackButton" 
    android:layout_marginRight="0dp" > 

scroll bar

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
dusm
  • 1,207
  • 4
  • 18
  • 24

5 Answers5

89

Create a scroll bar in drawable(scrollbar.xml) using this

<shape android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
         android:angle="45"
         android:centerColor="#65FF8215"
         android:endColor="#87FD2125"
         android:startColor="#65FF8215" />
    <corners android:radius="20dp" />
</shape>

and add this scroll bar like android:scrollbarThumbVertical="@drawable/scrollbar" to your ListView

OR

put the following attribute to your layout

android:scrollbarThumbVertical="@android:color/white"

OR

create a image and put it in drawable. then add the following property to your layout

android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"
Adhikari Bishwash
  • 2,770
  • 28
  • 32
43

put the following attribute to your layout

android:scrollbarThumbVertical="@android:color/white"

or create a image and put it in drawable. then add the following property to your layout

android:scrollbarThumbVertical="@drawable/scroll_bar_vertical"
Dehan Wjiesekara
  • 3,152
  • 3
  • 32
  • 46
12

Try this beautiful custom scrollview

Add following tags in your scrollview

    android:fadeScrollbars="false"
    android:scrollbarStyle="insideInset"
    android:scrollbarThumbVertical="@drawable/scrollview_thumb"
    android:scrollbarTrackVertical="@drawable/vertical_scrollview_track"

Create following drawable in your drawable folder

scrollview_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="@color/common_google_signin_btn_text_light_focused" />
<corners android:radius="15dp" />

</shape>

vertical_scrollview_traack.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="#E2E0EB" />
<stroke
    android:width="1dp"
    android:color="#b3a9a9" />
<size android:width="15dp" />
<corners android:radius="15dp" />
</shape>

Output

enter image description here

Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159
11

Taken from this question:

You can set Listview property as or put the following attribute to your scrollview:

android:scrollbarThumbVertical="@drawable/custom_scroll_style"

Here custom_scroll_style is a xml file under the drawable folder. Lets create the custom_scroll_style.xml.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
android:angle="45"
android:endColor="#FF3401"
android:centerColor="#ff5c33"
android:startColor="#FF3401" />

<corners android:radius="8dp" />

</shape>
Community
  • 1
  • 1
M D
  • 47,665
  • 9
  • 93
  • 114
  • Do you know how to change the thickness of the scrollbar? – Michael Yaworski Dec 26 '13 at 09:20
  • @mike yaworski This link may be help to you:[custom-scrollbar-graphics-in-android](http://porcupineprogrammer.blogspot.in/2012/08/custom-scrollbar-graphics-in-android.html) – M D Dec 26 '13 at 09:26
  • 1
    @mikeyaworski You can use android:scrollbarSize to change width of vertical scrollbar and height of horizontal scrollbar. – Rahul Sainani Feb 11 '14 at 10:20
0

The question is: "how to change color"

The only correct answer is one! code line in your layout:

android:scrollbarThumbVertical="@android:color/white"

Thats all!

p.s. The question is simple: "color"! and the answer is very simple too. Not a: "how to set custom bar", "how to change bar sizes" or etc. Why so many long answers...

Vitaly
  • 334
  • 4
  • 14
  • This is the same solution as in [the accepted answer](https://stackoverflow.com/a/20781845/2227743) (the second example). – Eric Aya Aug 17 '21 at 09:23
  • 1
    The question is simple and solution is very! simple - Dont need any second or third examples. I don't want and don't need to read all these variants. Just one line of code -That All. – Vitaly Aug 18 '21 at 10:07