Search code examples
listviewbackground-colorkivylistadapter

Kivy - ListAdapter background color


Simple problem: I want to set the background color for my ListAdapter, cls = ListItemButton. Whatever I do, it stays the same ugly green (and red on press). Of course i tried background_color, made a custom rule for ListItemButton, etc, nothing works ...

kv code:

ListView:
    adapter:
        ListAdapter(data=["1","2"], cls=ListItemButton)

nothing special in my py file. Any help is greatly appreciated!


Solution

  • You just need to override the selected_color and deselected_color properties of the ListItemButton. The easiest way to do this is with a kv class rule, which will affect all instances of ListItemButton:

    #:import ListAdapter kivy.adapters.listadapter.ListAdapter
    #:import ListItemButton kivy.uix.listview.ListItemButton
    <ListItemButton>:
        selected_color: 0, 0, 1, 1
        deselected_color: 0, 0, 0, 1
    
    ListView:
        adapter:
            ListAdapter(data=["1","2"], cls=ListItemButton)