The scrollbar in my scrollview is only visible when I start scrolling. How can I always show it?
As of now the best way is to use android:fadeScrollbars="false"
in xml which is equivalent to ScrollView.setScrollbarFadingEnabled(false);
in java code.
Setting the android:scrollbarFadeDuration="0"
will do the trick.
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!
Don't forget to add android:scrollbars="vertical"
along with android:fadeScrollbars="false"
or it won't show at all in some cases.
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.
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.
Try android:scrollbarAlwaysDrawVerticalTrack="true"
for vertical. and Try android:scrollbarAlwaysDrawHorizontalTrack="true"
for horizontal
Since neither of the above worked for me, here's what did: android:scrollbarDefaultDelayBeforeFade="500000"
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!
These two together worked for me:
android:scrollbarFadeDuration="0"
android:scrollbarAlwaysDrawVerticalTrack="true"
I had the same problem. The bar had the same background color. Try:
android:scrollbarThumbVertical="@android:color/black"
setVertical* helped to make vertical scrollbar always visible programmatically
scrollView.setScrollbarFadingEnabled(false);
scrollView.setVerticalScrollBarEnabled(true);
scrollView.setVerticalFadingEdgeEnabled(false);
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"`
use awakenScrollBars() awake scrollbar draw.
Success story sharing
view.setScrollBarFadeDuration(0);
setScrollBarFadeDuration(0)
), becausesetScrollbarFadingEnabled(false)
doesn't work everywheresetScrollBarFadeDuration(0);
is more reliable