Android Code Snippet Switch Colors

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

  1. Erel

    Erel Administrator Staff Member Licensed User



    Sub SetSwitchColors (Switch As Switch, On As Int, Off As Int)
    Dim p As Phone
    If p.SdkVersion < 16 Then Return
    Dim DrawableCompat As JavaObject
    Dim jo As JavaObject = Switch
    "setTintList"Array(jo.RunMethod("getThumbDrawable"Null), CreateColorStateList(On, Off)))
    End Sub

    'Based on:
    Sub CreateColorStateList(On As Int,Off As Int) As Object
    Dim sd As StateListDrawable 'ignore
       Dim States(2,1As Int
    0,0) = sd.State_Checked
    1,0) = sd.State_Enabled
    Dim CSL As JavaObject
    "android.content.res.ColorStateList",Array(States, Array As Int(On, Off)))
    Return CSL
    End Sub

    Depends on: JavaObject, Phone
  2. appie21

    appie21 Active Member Licensed User

    i want add colors to my switch
    Dim SwNoti As Switch
    How to activate these code (on that switch)?
  3. Erel

    Erel Administrator Staff Member Licensed User

    Mashiane likes this.
  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