Android Code Snippet Change CheckBox colors

Discussion in 'Code Snippets' started by Erel, May 7, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    1. Add:
    Code:
    #AdditionalJar: com.android.support:support-compat
    2:
    Code:
    Sub SetButtonTintList(View As View, Disabled As Int, Enabled As Int)
       
    Dim States(2,1As Int
       
    Dim sd As StateListDrawable 'ignore
       States(00) = sd.State_Enabled
       States(
    10) = sd.State_Disabled
       
    Dim Color(2As Int = Array As Int(Enabled, Disabled)
       
    Dim CSL As JavaObject
       CSL.InitializeNewInstance(
    "android.content.res.ColorStateList",Array(States,Color))
       
    Dim jo As JavaObject
       jo.InitializeStatic(
    "android.support.v4.widget.CompoundButtonCompat")
       jo.RunMethod(
    "setButtonTintList"Array(View, CSL))
    End Sub
    Usage example:
    Code:
    For Each v As View In Activity.GetAllViewsRecursive
       
    If v Is CheckBox Then
           SetButtonTintList(v, 
    Colors.Red, Colors.Blue)
       
    End If
    Next
    Note that it only has effect on Android 5+ devices.
     
    paragkini, vecino, hatzisn and 5 others like this.
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