Android Code Snippet Scrollbar Color

Discussion in 'Code Snippets' started by Erel, Feb 21, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This code uses reflection to change the ScrollView scroll bar color:

    [​IMG]

    Code:
    Sub SetScrollbarColor(sv As ScrollView, clr As Int)
       
    Dim r As Reflector
       r.Target = sv
       r.Target = r.GetField(
    "mScrollCache")
       r.Target = r.GetField(
    "scrollBar")
       
    Dim cd As ColorDrawable
       cd.Initialize(clr, 
    5dip)
       r.RunMethod4(
    "setVerticalThumbDrawable"Array(cd), Array As String("android.graphics.drawable.Drawable"))
    End Sub
    Note that it is based on private API so it can be broken in a future version of Android.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice