Android Question CustomListView and Hololight theme

Discussion in 'Android Questions' started by Alberto Michelis, Jun 20, 2015.

  1. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Using the Holo-Light theme with a CustomListView the color indicator when I click the ite goes away.
    Not using the theme I get a yellow backgroun color when I click in the item.
    I want it (not in yellow) to go back.
    How can I do it?
  2. Erel

    Erel Administrator Staff Member Licensed User

    The "pressed" color disappears in all themes. The colors are managed by StateListDrawable (line #135).
  3. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    You mean I cant change it? or
    Where to find StateListDrawable to modify line 135?
  4. Erel

    Erel Administrator Staff Member Licensed User

    I mean that the expected behavior is that the background color disappears. If you like to change the behavior then you need to modify the code. The relevant code starts in line #135.
  5. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Sory I need more help line 135 of what? of the custom list view code?
    Im lost...
  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Yes in the CustomListView code, it's where the pressed state is set and Erel originally used a method to get the pressed state based on the theme...
    Public Sub InsertAt(Index As Int, Pnl As Panel, ItemHeight As Int, Value As Object)
    Dim sd As StateListDrawable
        sd.AddState(sd.State_Pressed, pressedDrawable)
    'create another panel to handle the click event
        Dim p As Panel
        p.Background = sd
    Dim cd As ColorDrawable
    Colors.Transparent, 0)
        Pnl.Background = cd
    00, sv.Width, ItemHeight)
        p.Tag = Index
    Where pressedDrawable was set as follows...

    Dim R As Reflector
    Dim idPressed As Int
           idPressed = R.GetStaticField(
        R.Target = R.GetContext
        R.Target = R.RunMethod(
        pressedDrawable = R.RunMethod2(
    "getDrawable", idPressed, "")
    @Erel likes fancy code :D, a simple way to set the states is shown below (copied from elsewhere on the Forum but I forget where, I only know that Roger Garstang originally provided it as I always give credit to the original author of code snippets in all of my Apps). You can modify the pressed state to be whatever you want.

    'My call to get the StateListDrawable
    btnEnter.Background  = getButtonGradient(Array As Int(Colors.RGB(5020550), Colors.RGB(0,128,0)))

    'The sub which returns a StateListDrawable
    Private Sub getButtonGradient(intColorList() As Int) As StateListDrawable ' Courtesy of B4A user Roger Garstang
        ' Define GradientDrawable for Enabled state
        Dim gdwEnabled As GradientDrawable
    "TOP_BOTTOM", intColorList)
        gdwEnabled.CornerRadius = 

    ' Define GradientDrawable for Pressed state
        Dim gdwPressed As GradientDrawable
    "LEFT_RIGHT", intColorList)
        gdwPressed.CornerRadius = 

    ' Define StateListDrawable
        Dim stdGradient As StateListDrawable
    Array As Int(stdGradient.State_enabled, -stdGradient.State_Pressed), gdwEnabled)
        stdGradient.AddState(stdGradient.State_Pressed, gdwPressed)
    Return stdGradient
    End Sub
    DonManfred, mangojack and LucaMs like 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