Hide scrollbar in ScrollView

后端 未结 11 1527
时光说笑
时光说笑 2020-12-14 05:19

I have an app with a ScrollView, and I don\'t want the scrollbar to appear on the screen. How can I hide the scrollbar in a ScrollView while making sure scrolling still work

相关标签:
11条回答
  • 2020-12-14 06:01

    Now the scroll does not work anymore if u set android:scrollbars="none"

    I have solved the problem with

      android:scrollbars="vertical" // or horizontal
    

    and setting its size to 0 dp

      android:scrollbarSize="0dp"
    
    0 讨论(0)
  • 2020-12-14 06:10

    In XML set android:scrollbars="none"

    0 讨论(0)
  • 2020-12-14 06:10

    Kotlin Solution

    If you need to do this programmatically, you can set either one or both of:

    scrollView.isHorizontalScrollBarEnabled = false
    scrollView.isVerticalScrollBarEnabled = false
    

    If you'll be applying both regularly, try adding this extension

    fun ScrollView.noScrollbars() {
        isHorizontalScrollBarEnabled = false
        isVerticalScrollBarEnabled = false
    }
    

    To easily allow switching, you can add an optional boolean

    fun ScrollView.noScrollbars(hide: Boolean = true) {
        isHorizontalScrollBarEnabled = !hide
        isVerticalScrollBarEnabled = !hide
    }
    
    0 讨论(0)
  • 2020-12-14 06:16

    In my experience,

    android:scrollbarThumbVertical="@null"
    

    can cause NullPointerException in older devices. Use this instead:

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

    Cheers!

    0 讨论(0)
  • 2020-12-14 06:16

    For hiding a vertical scrollbar, do this in the XML:

    android:scrollbarThumbVertical="@null"
    

    And for Hiding horizontal scrollbar do this :

    android:scrollbarThumbHorizontal="@null"
    

    The above lines of codes will work if you want to hide the scrollbar without disabling it.

    And for disabling a scrollbar, write this:

    android:scrollbars="none"
    
    0 讨论(0)
提交回复
热议问题