Sub SetNinePatchButton2(Btn As Button, DefaultImage As String, PressedImage As String, _
DisabledImage As String, FocusedImage As String, FocusedDisabledImage As String)
Dim r As Reflector
Dim package As String
package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
Dim sd As StateListDrawable
sd.Initialize
Dim idDefault, idPressed, idFocused, idDisabled, idFocusedDisabled As Int
If FocusedDisabledImage.Length > 0 Then
idFocusedDisabled = r.GetStaticField(package & ".R$drawable", FocusedDisabledImage)
sd.AddState2(Array As Int (sd.State_Disabled, 0x0101009c), r.RunMethod2("getDrawable", idFocusedDisabled, "java.lang.int"))
End If
If DisabledImage.Length > 0 Then
idDisabled = r.GetStaticField(package & ".R$drawable", DisabledImage)
sd.AddState(sd.State_Disabled, r.RunMethod2("getDrawable", idDisabled, "java.lang.int"))
End If
If PressedImage.Length > 0 Then
idPressed = r.GetStaticField(package & ".R$drawable", PressedImage)
sd.AddState(sd.State_Pressed, r.RunMethod2("getDrawable", idPressed, "java.lang.int"))
End If
If FocusedImage.Length > 0 Then
idFocused = r.GetStaticField(package & ".R$drawable", FocusedImage)
sd.AddState(0x0101009c, r.RunMethod2("getDrawable", idFocused, "java.lang.int"))
End If
If DefaultImage.Length > 0 Then
idDefault = r.GetStaticField(package & ".R$drawable", DefaultImage)
sd.AddCatchAllState( r.RunMethod2("getDrawable", idDefault, "java.lang.int"))
End If
Btn.Background = sd
End Sub