How to set scrollbar thumb programmatically in Android?

后端 未结 3 509
野趣味
野趣味 2020-12-14 11:04

I know listview can set scrollbar thumb in XML like this Android:scrollbarThumbVertical etc.

But I\'m creating a listview instance in the java code and

3条回答
  •  再見小時候
    2020-12-14 11:30

    I didn't know the answer to this, but after a bit of digging around I don't think it's possible without a load of hassle.

    This xml attribute is actually associated with a View, not a ListView - In the Android View source code, it seems that the only place that it is setting the vertical thumb drawable is the 'initializeScrollbars' method. Now this method isn't private, so we can extend any child of View and override this method, but the issue is that a crucial component needed to set the thumb drawable, the ScrollabilityCache, is private without any getter methods.

    So without rewriting a lot of the code I don't think there's any easy way to do this - sorry!

提交回复
热议问题