Hi,
The following color change example works well on lower versions of Android because "android.graphics.drawable.drawable" is an abstract class and is based on a private API which in higher versions of Android throws an error: noSuchMethodException.
I am looking for a working code for android version 12, could someone help me, thank you very much in advance.
'noSuchMethodException: >= SDK30:
Public 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
Private Sub ChangeScrollbarColor(v As B4XView, Drawable As Object)
Dim p As Phone
If p.SdkVersion >= 29 Then
v.As(JavaObject).RunMethod("setVerticalScrollbarThumbDrawable", Array(Drawable))
End If
End Sub
Usage:
B4X:
Dim cd As ColorDrawable
cd.Initialize(xui.Color_Red, 5dip)
ChangeScrollbarColor(ScrollView1, cd)
Note that it will work with xCLV as well. You need to pass clv.sv as the view.