Android Question CustomListView Background Color

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

  1. rQb

    rQb Member Licensed User

    Hi

    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

    BR
     
  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
    Code:
    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:
    Code:
    ...
    clv1.BackgroundColor(
    Colors.Red)
    ...
    stefan
     
    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

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

    Code:
    Dim sd As StateListDrawable
        sd.Initialize
        sd.AddState(sd.State_Pressed, pressedDrawable)
        sd.AddCatchAllState(Pnl.Background)

        
    'create another panel to handle the click event
        Dim p As Panel
        p.Initialize(
    "panel")
        p.Background = sd
        
    Dim cd As ColorDrawable
        cd.Initialize(
    Colors.Transparent, 0)
        Pnl.Background = cd
        p.AddView(Pnl, 
    00, sv.Width, ItemHeight)
        p.Tag = Index



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

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

            
    'prosg Add gray divider
            Dim lblDivider As Label
            lblDivider.Initialize(
    "")
            lblDivider.Color = 
    Colors.RGB(247,247,247)
            p.AddView(lblDivider, 
    0,p.Height-1dip100%x1dip)

        sv.Panel.Height = sv.Panel.Height + ItemHeight + dividerHeight
        
    If items.Size = 1 Then sv.Panel.Height = sv.Panel.Height + dividerHeight
    End Sub
    regards
     
  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.
    Screenshot.png


    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
    Code:
    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.
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