315

The scrollbar in my scrollview is only visible when I start scrolling. How can I always show it?

Janusz
  • 187,060
  • 113
  • 301
  • 369
jul
  • 36,404
  • 64
  • 191
  • 318

15 Answers15

627

As of now the best way is to use android:fadeScrollbars="false" in xml which is equivalent to ScrollView.setScrollbarFadingEnabled(false); in java code.

TronicZomB
  • 8,667
  • 7
  • 35
  • 50
Rejinderi
  • 11,694
  • 2
  • 31
  • 40
  • for ListView didn't work, but this worked: `view.setScrollBarFadeDuration(0);` – user924 Dec 09 '17 at 17:24
  • 3
    so the right and accepted answer should be @Tanmay Mandal answer (`setScrollBarFadeDuration(0)`), because `setScrollbarFadingEnabled(false)` doesn't work everywhere – user924 Dec 09 '17 at 17:26
  • or it stops works for example because of like described here https://stackoverflow.com/a/6673848/7767664 (onStop, onStart again and faield), so `setScrollBarFadeDuration(0);` is more reliable – user924 Dec 09 '17 at 17:29
  • 1
    One thing to note is the scrollbar will not show when the view is not scrollable ✓ – James Jul 28 '22 at 19:15
  • I needed this on my recyclerview to both have the bar and always see it `android:scrollbars="vertical" android:fadeScrollbars="false"` – brando f Nov 22 '22 at 18:01
61

Setting the android:scrollbarFadeDuration="0" will do the trick.

Tanmay Mandal
  • 39,873
  • 12
  • 51
  • 48
56

There are 4 ways:

  • From Java code: ScrollView.setScrollbarFadingEnabled(false);
  • From XML code: android:fadeScrollbars="false"
  • From Java code: myView.setScrollBarFadeDuration(0)
  • From XML code: android:scrollbarFadeDuration="0"

Simple as that!

Top-Master
  • 7,611
  • 5
  • 39
  • 71
Tudor Luca
  • 6,259
  • 2
  • 29
  • 44
23

Don't forget to add android:scrollbars="vertical" along with android:fadeScrollbars="false" or it won't show at all in some cases.

Sir Codesalot
  • 7,045
  • 2
  • 50
  • 56
23

Style your scroll bar Visibility, Color and Thickness like this:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/recycler_bg"

        <!--Show Scroll Bar-->
        android:fadeScrollbars="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbarFadeDuration="50000"

        <!--Scroll Bar thickness-->
        android:scrollbarSize="4dp"

        <!--Scroll Bar Color-->
        android:scrollbarThumbVertical="@color/colorSecondaryText"/>

Hope it help save some time.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
13

Try this as the above suggestions didn't work for me when I wanted to do this for a TextView:

TextView.setScrollbarFadingEnabled(false);

Good Luck.

Camille Sévigny
  • 5,104
  • 4
  • 38
  • 61
11

Simple and easy. Add this attribute to the ScrollBar:

android:fadeScrollbars="false"

Or you can do this in :

scrollView.setScrollbarFadingEnabled(false);

Or in :

scrollView.isScrollbarFadingEnabled = false
Boken
  • 4,825
  • 10
  • 32
  • 42
Gourav
  • 2,746
  • 5
  • 28
  • 45
10

Try android:scrollbarAlwaysDrawVerticalTrack="true" for vertical. and Try android:scrollbarAlwaysDrawHorizontalTrack="true" for horizontal

Saurabh Pareek
  • 7,126
  • 4
  • 28
  • 29
9

Since neither of the above worked for me, here's what did: android:scrollbarDefaultDelayBeforeFade="500000"

Emir Kuljanin
  • 3,881
  • 1
  • 25
  • 30
9

android:scrollbarFadeDuration="0" sometimes does not work after I exit from the apps and start again. So I add gallery.setScrollbarFadingEnabled(false); to the activity and it works!

icegee
  • 111
  • 1
  • 6
8

These two together worked for me:

android:scrollbarFadeDuration="0"
android:scrollbarAlwaysDrawVerticalTrack="true"
sealskej
  • 7,281
  • 12
  • 53
  • 64
6

I had the same problem. The bar had the same background color. Try:

android:scrollbarThumbVertical="@android:color/black"
Boris Karloff
  • 1,190
  • 12
  • 20
4

setVertical* helped to make vertical scrollbar always visible programmatically

scrollView.setScrollbarFadingEnabled(false);
scrollView.setVerticalScrollBarEnabled(true);
scrollView.setVerticalFadingEdgeEnabled(false);
Dmitry Bryliuk
  • 106
  • 1
  • 3
4

Setting this will do the trick. Change the @drwable for own style.

android:scrollbars="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:fadeScrollbars="false"
            android:scrollbarThumbVertical="@drawable/scroll"`
Gourav
  • 2,746
  • 5
  • 28
  • 45
Muthu Krishnan
  • 196
  • 1
  • 10
-1

use awakenScrollBars() awake scrollbar draw.