Android Question CustomListView Background Color

Discussion in 'Android Questions' started by rQb, May 1, 2015.

  1. rQb

    rQb Member Licensed User


    Cant locate where I can set the background color of a CLV if panels dont fill out the total area of the CLV. Currently its white but want it to match activity (black).

    Thanks in advance

  2. eurojam

    eurojam Well-Known Member Licensed User

    CustomListView is a class based on a Scrollview where you can set the background. You can extent the class with a backgroundcolor, for example put this sub to the class CustomListView
    Public Sub BackgroundColor(c As Int)
    Dim aP As Panel
      aP = sv.Panel
      aP.Color = c
    End Sub
    then you will have the possibility to set the background in your activity code like:
    stingrae likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    This line sets the background color: sv.Color = 0xFFD9D7DE 'this sets the dividers color (in Initialize sub).
    stingrae likes this.
  4. Prosg

    Prosg Active Member Licensed User

    I do this who work fine :

    I want a background white so i did in Public Sub Initialize

    sv.Color = Colors.White
    and i add some code in ublic Sub InsertAt

    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

    If Index = items.Size Then
    Dim top As Int
    If Index = 0 Then top = dividerHeight Else top = sv.Panel.Height
    0, top, sv.Width, ItemHeight)
    Dim top As Int
    If Index = 0 Then
                top = dividerHeight
    Dim previousPanel As Panel
                previousPanel = panels.Get(Index - 
                top = + previousPanel.Height + dividerHeight
    End If

    Dim p2 As Panel
    For i = Index To panels.Size - 1
                p2 = panels.Get(i)
       = + ItemHeight + dividerHeight
                p2.Tag = i + 
            items.InsertAt(Index, Value)
            panels.InsertAt(Index, p)
    0, top, sv.Width, ItemHeight)
    End If

    'prosg Add gray divider
            Dim lblDivider As Label
            lblDivider.Color = 

        sv.Panel.Height = sv.Panel.Height + ItemHeight + dividerHeight
    If items.Size = 1 Then sv.Panel.Height = sv.Panel.Height + dividerHeight
    End Sub
  5. Anser

    Anser Well-Known Member Licensed User

    I have a CustomListView with its height defined as 100%y. Depending on the available data, the CustomListView may contain many panels and if the data is less then the CustomListView will contain only one or two panels and this may not fill the entire screen length.

    Unfortunately, if the CustomListView does not contain enough panels then the background appears to be grey color.

    A screen snapshot of what I am trying to explain.

    My Activity's Background color is white. I did not see any property in Designer also to get this done.

    What is the best way to fill the background color of CustomListView with any color that the programmer wish to show and that doesn't effect the divider color ?

    The code posted by the user Prosg is working

    After adding the code by Prosg the following line in the Activity does the work
    clv.AsView.Color = Colors.White
    I prefer not to modify the Original Class.

    Is this the expected behavior OR am I missing something ? Any help will be appreciated.
    Last edited: Jun 17, 2016
    Kevin Golding 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