How to always show scrollbar

天大地大妈咪最大 提交于 2020-01-09 02:53:41

问题


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


回答1:


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




回答2:


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




回答3:


There are 2 ways:

  • from Java code: ScrollView.setScrollbarFadingEnabled(false);
  • from XML code: android:fadeScrollbars="false"

Simple as that!




回答4:


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.




回答5:


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




回答6:


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




回答7:


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!




回答8:


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




回答9:


These two together worked for me:

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



回答10:


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.




回答11:


setVertical* helped to make vertical scrollbar always visible programmatically

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



回答12:


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

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



回答13:


Simple and easy. Add this attribute to the ScrollBar:

android:fadeScrollbars="false"

Or you can do this in java:

scrollView.setScrollbarFadingEnabled(false);



回答14:


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


来源:https://stackoverflow.com/questions/5702502/how-to-always-show-scrollbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!