Example of using MDDropDownItem:
from kivy .lang import Builder
from kivy .metrics import dp
from kivy .properties import StringProperty
from kivymd .uix .list import OneLineIconListItem
from kivymd .app import MDApp
from kivymd .uix .menu import MDDropdownMenu
KV = '''
<IconListItem>
IconLeftWidget:
icon: root.icon
MDScreen
MDDropDownItem:
id: drop_item
pos_hint: {'center_x': .5, 'center_y': .5}
text: 'Item 0'
on_release: app.menu.open()
'''
class IconListItem (OneLineIconListItem ):
icon = StringProperty ()
class Test (MDApp ):
def __init__ (self , ** kwargs ):
super ().__init__ (** kwargs )
self .screen = Builder .load_string (KV )
menu_items = [
{
"viewclass" : "IconListItem" ,
"icon" : "git" ,
"text" : f"Item { i } " ,
"height" : dp (56 ),
"on_release" : lambda x = f"Item { i } " : self .set_item (x ),
} for i in range (5 )
]
self .menu = MDDropdownMenu (
caller = self .screen .ids .drop_item ,
items = menu_items ,
position = "center" ,
width_mult = 4 ,
)
self .menu .bind ()
def set_item (self , text_item ):
self .screen .ids .drop_item .set_item (text_item )
self .menu .dismiss ()
def build (self ):
return self .screen
Test ().run ()