Kivy - Background color in the listAdapter

Simple problem: I want to set the background color for my list, cls = ListItemButton. Whatever I do, it stays the same ugly green (and red when pressed). Of course I tried background_color, created my own rule for the ListItemButton, etc., Nothing works ...

kv code:

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

      

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

+3


source to share


1 answer


You just need to override the properties selected_color

and deselected_color

ListItemButton

. The easiest way to do this is with a kv class rule that will affect all instances 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)

      

+5


source







All Articles