24

How I can make this scrollbar:

Idrizi.A
  • 9,819
  • 11
  • 47
  • 88
Unmerciful
  • 1,325
  • 4
  • 21
  • 38
  • this will help you http://stackoverflow.com/questions/8355984/can-we-have-a-custom-scrollbar-on-an-scrollview & Second is http://stackoverflow.com/questions/4485170/android-scrollbar-with-a-extra-view-screenshot-included – Dixit Patel Jan 05 '13 at 12:41
  • It didn't help me, unfortunately. – Unmerciful Jan 05 '13 at 12:56

2 Answers2

32

To change the thumb image you can simply create the following style and apply it to your ScrollView:

<style name="your_style_name">  
    <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
    <item name="android:scrollbarStyle">outsideOverlay</item>
    <item name="android:scrollbars">vertical</item>
    <item name="android:fadeScrollbars">false</item>
    <item name="android:scrollbarThumbVertical">@drawable/scroller_thumb</item>
</style>

where scroller_thumb is your custom image for the scroller thumb.

also note the following attributes:

  1. "android:fadeScrollbars" which is set to false to make the thumb image stay permanently.
  2. "android:scrollbarStyle" which is set to outsideOverlay to make the thumb image drawn at the "Edge of the view and overlaid" as stated here: android:scrollbarStyle

Now, in order to put the thin line you want under the scroller, simply add an image view containing the line image, to the direct child of the ScrollView (RelativeLayout child as a direct child for the ScrollView will allow you to position the image on the right side of the view - so this is would have been my choice).

and that's it.

Daniel L.
  • 5,060
  • 10
  • 36
  • 59
11

Setting android:scrollbarThumbVertical is not the best solution, it will stretch the thumb image according to the list size...

You'd better use android:fastScrollThumbDrawable

Here's an example:

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fadeScrollbars="false"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:scrollbarSize="0dip"
    android:scrollbarStyle="outsideInset"
    android:fastScrollAlwaysVisible="true"
    android:fastScrollEnabled="false"
    android:scrollbars="vertical" />

Then on the styles.xml AppTheme you add

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:fastScrollThumbDrawable">@drawable/scroller_style</item>
</style>

and on the res/drawable folder you create the file: scroller_style.xml with the content

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

    <item android:drawable="@drawable/scroller_active" android:state_pressed="true"/>
    <item android:drawable="@drawable/scroller"/>

</selector>

where scroller is your thumb image and scroller_active is your active thumb image (optional)

Bruno
  • 543
  • 2
  • 7
  • 21