Dropdown Item

Example

from kivymd.app import MDApp
from kivy.factory import Factory
from kivy.lang import Builder

from kivymd.theming import ThemeManager

Builder.load_string(
    '''
#:import toast kivymd.toast.toast


<MyRoot@BoxLayout>
    orientation: 'vertical'

    MDToolbar:
        title: "Test MDDropDownItem"
        md_bg_color: app.theme_cls.primary_color
        elevation: 10
        left_action_items: [['menu', lambda x: x]]

    FloatLayout:

        MDDropDownItem:
            id: dropdown_item
            pos_hint: {'center_x': 0.5, 'center_y': 0.6}
            items: app.items
            dropdown_bg: [1, 1, 1, 1]

        MDRaisedButton:
            pos_hint: {'center_x': 0.5, 'center_y': 0.3}
            text: 'Chek Item'
            on_release: toast(dropdown_item.current_item)
''')


class Test(MDApp):

    def build(self):
        self.items = [f"Item {i}" for i in range(50)]
        return Factory.MyRoot()


Test().run()

API - kivymd.uix.dropdownitem

class kivymd.uix.dropdownitem.MDDropDownItem(**kwargs)

Bases: kivymd.theming.ThemableBehavior, kivy.uix.boxlayout.BoxLayout

Events

on_select

Called when an item is selected

items

String list of items for a drop-down list.

dropdown_bg

Color of the background of the menu.

dropdown_max_height

The menu will grow no bigger than this number.

dropdown_width_mult

This number multiplied by the standard increment (56dp on mobile, 64dp on desktop, determines the width of the menu items.

If the resulting number were to be too big for the application Window, the multiplier will be adjusted for the biggest possible one.

current_item

Current label of item MDDropDownItem class.

on_items(self, instance, value)
set_item(self, name_item)
on_select(self, value)
on_touch_down(self, touch)