jul
jul

Reputation: 37484

How to always show scrollbar

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

Upvotes: 324

Views: 189715

Answers (15)

Tudor Luca
Tudor Luca

Reputation: 6419

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!

Upvotes: 60

李亮亮
李亮亮

Reputation: 1

use awakenScrollBars() awake scrollbar draw.

Upvotes: -1

Gourav
Gourav

Reputation: 2819

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

Upvotes: 12

Boris Karloff
Boris Karloff

Reputation: 1328

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

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

Upvotes: 7

Muthu Krishnan
Muthu Krishnan

Reputation: 206

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"`

Upvotes: 4

Hitesh Sahu
Hitesh Sahu

Reputation: 45110

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.

Upvotes: 25

Sir Codesalot
Sir Codesalot

Reputation: 7293

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

Upvotes: 24

Dmitry Bryliuk
Dmitry Bryliuk

Reputation: 106

setVertical* helped to make vertical scrollbar always visible programmatically

scrollView.setScrollbarFadingEnabled(false);
scrollView.setVerticalScrollBarEnabled(true);
scrollView.setVerticalFadingEdgeEnabled(false);

Upvotes: 4

Rejinderi
Rejinderi

Reputation: 11844

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

Upvotes: 638

icegee
icegee

Reputation: 111

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!

Upvotes: 9

Emir Kuljanin
Emir Kuljanin

Reputation: 3911

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

Upvotes: 9

sealskej
sealskej

Reputation: 7431

These two together worked for me:

android:scrollbarFadeDuration="0"
android:scrollbarAlwaysDrawVerticalTrack="true"

Upvotes: 8

Camille S&#233;vigny
Camille S&#233;vigny

Reputation: 5143

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.

Upvotes: 13

Saurabh Pareek
Saurabh Pareek

Reputation: 7134

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

Upvotes: 11

Tanmay Mandal
Tanmay Mandal

Reputation: 40178

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

Upvotes: 62

Related Questions