Android Code Snippet ColorStateList as object for view properties

Discussion in 'Code Snippets' started by fredo, Oct 1, 2016.

Similar threads

B4A Tutorial Cards list with CustomListView
B4A Code Snippet Change CheckBox colors
B4A Code Snippet Change EditText Colors
B4A Code Snippet Switch Colors
B4A Code Snippet ColorStateList
B4A Library [B4X] XUI Views - Cross platform views and dialogs
  1. fredo

    fredo Active Member Licensed User

    While working with @DonManfred 's wrap of the VectorCompat library I needed to set a ColorStateList to
    a VectorDrawable ForegroundTintList property.

    After fiddling around with xml files in the drawable folder I needed a more flexible way to set the foreground colors and found a snippet from @stevel05 here and modified it a little bit to use it as object.

    01-10-_2016_19-59-30.jpg


    Code:
    Sub GetColorStatelist(intColorPressed As Int, intColorEnabled As Int, intColorDisabled As Int) As JavaObject
        
    Dim States(3,1As Int
        States(
    0,0) = 16842919  'Pressed
        States(1,0) = 16842910  'Enabled
        States(2,0) = -16842910 'Disabled
        Dim Color(3As Int = Array As Int(intColorPressed, intColorEnabled, intColorDisabled)
        
    Dim csl As JavaObject
        csl.InitializeNewInstance(
    "android.content.res.ColorStateList",Array As Object(States,Color))
        
    '
        Return csl
        
    '
    End Sub
     
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