Bottom Sheet¶
See also
Bottom sheets are surfaces containing supplementary content that are anchored to the bottom of the screen.
Two classes are available to you MDListBottomSheet and MDGridBottomSheet
for standard bottom sheets dialogs:
Usage MDListBottomSheet¶
from kivy.lang import Builder
from kivymd.toast import toast
from kivymd.uix.bottomsheet import MDListBottomSheet
from kivymd.app import MDApp
KV = '''
Screen:
MDToolbar:
title: "Example BottomSheet"
pos_hint: {"top": 1}
elevation: 10
MDRaisedButton:
text: "Open list bottom sheet"
on_release: app.show_example_list_bottom_sheet()
pos_hint: {"center_x": .5, "center_y": .5}
'''
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
def callback_for_menu_items(self, *args):
toast(args[0])
def show_example_list_bottom_sheet(self):
bottom_sheet_menu = MDListBottomSheet()
for i in range(1, 11):
bottom_sheet_menu.add_item(
f"Standart Item {i}",
lambda x, y=i: self.callback_for_menu_items(
f"Standart Item {y}"
),
)
bottom_sheet_menu.open()
Example().run()
The add_item method of the MDListBottomSheet
class takes the following arguments:
text - element text;
callback - function that will be called when clicking on an item;
There is also an optional argument icon,
which will be used as an icon to the left of the item:
Using the MDGridBottomSheet class is similar
to using the MDListBottomSheet class:
from kivy.lang import Builder
from kivymd.toast import toast
from kivymd.uix.bottomsheet import MDGridBottomSheet
from kivymd.app import MDApp
KV = '''
Screen:
MDToolbar:
title: 'Example BottomSheet'
pos_hint: {"top": 1}
elevation: 10
MDRaisedButton:
text: "Open grid bottom sheet"
on_release: app.show_example_grid_bottom_sheet()
pos_hint: {"center_x": .5, "center_y": .5}
'''
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
def callback_for_menu_items(self, *args):
toast(args[0])
def show_example_grid_bottom_sheet(self):
bottom_sheet_menu = MDGridBottomSheet()
data = {
"Facebook": "facebook-box",
"YouTube": "youtube",
"Twitter": "twitter-box",
"Da Cloud": "cloud-upload",
"Camera": "camera",
}
for item in data.items():
bottom_sheet_menu.add_item(
item[0],
lambda x, y=item[0]: self.callback_for_menu_items(y),
icon_src=item[1],
)
bottom_sheet_menu.open()
Example().run()
You can use custom content for bottom sheet dialogs:
from kivy.lang import Builder
from kivymd.uix.bottomsheet import MDCustomBottomSheet
from kivymd.app import MDApp
KV = '''
<ItemForCustomBottomSheet@OneLineIconListItem>
on_press: app.custom_sheet.dismiss()
icon: ""
IconLeftWidget:
icon: root.icon
<ContentCustomSheet@BoxLayout>:
orientation: "vertical"
size_hint_y: None
height: "400dp"
MDToolbar:
title: 'Custom bottom sheet:'
ScrollView:
GridLayout:
cols: 1
size_hint_y: None
height: self.minimum_height
ItemForCustomBottomSheet:
icon: "page-previous"
text: "Preview"
ItemForCustomBottomSheet:
icon: "exit-to-app"
text: "Exit"
Screen:
MDToolbar:
title: 'Example BottomSheet'
pos_hint: {"top": 1}
elevation: 10
MDRaisedButton:
text: "Open custom bottom sheet"
on_release: app.show_example_custom_bottom_sheet()
pos_hint: {"center_x": .5, "center_y": .5}
'''
class Example(MDApp):
custom_sheet = None
def build(self):
return Builder.load_string(KV)
def show_example_custom_bottom_sheet(self):
self.custom_sheet = MDCustomBottomSheet(screen=Factory.ContentCustomSheet())
self.custom_sheet.open()
Example().run()
Note
When you use the MDCustomBottomSheet class, you must specify
the height of the user-defined content exactly, otherwise dp(100)
heights will be used for your ContentCustomSheet class:
<ContentCustomSheet@BoxLayout>:
orientation: "vertical"
size_hint_y: None
height: "400dp"
Note
The height of the bottom sheet dialog will never exceed half the height of the screen!
API - kivymd.uix.bottomsheet¶
-
class
kivymd.uix.bottomsheet.MDBottomSheet¶ Bases:
kivymd.theming.ThemableBehavior,kivy.uix.modalview.ModalView-
background¶ Private attribute.
-
duration_opening¶ The duration of the bottom sheet dialog opening animation.
duration_openingis anNumericPropertyand defaults to 0.15.
-
radius¶ The value of the rounding of the corners of the dialog.
radiusis anNumericPropertyand defaults to 25.
-
radius_from¶ Sets which corners to cut from the dialog. Available options are: (“top_left”, “top_right”, “top”, “bottom_right”, “bottom_left”, “bottom”).
radius_fromis anOptionPropertyand defaults to None.
-
animation¶ To use animation of opening of dialogue of the bottom sheet or not.
animationis anBooleanPropertyand defaults to False.
-
bg_color¶ Dialog background color in
rgbaformat.bg_coloris anListPropertyand defaults to [].
-
value_transparent¶ Background transparency value when opening a dialog.
value_transparentis anListPropertyand defaults to [0, 0, 0, 0.8].
-
open(self, *largs)¶
-
add_widget(self, widget, index=0, canvas=None)¶
-
on_dismiss(self)¶
-
resize_content_layout(self, content, layout, interval=0)¶
-
-
class
kivymd.uix.bottomsheet.MDCustomBottomSheet(**kwargs)¶ Bases:
kivymd.uix.bottomsheet.MDBottomSheet-
screen¶ Custom content.
screenis anObjectPropertyand defaults to None.
-
-
class
kivymd.uix.bottomsheet.MDListBottomSheet(**kwargs)¶ Bases:
kivymd.uix.bottomsheet.MDBottomSheet-
sheet_list¶ sheet_listis anObjectPropertyand defaults to None.
-
add_item(self, text, callback, icon=None)¶ - Parameters
text – element text;
callback – function that will be called when clicking on an item;
icon_src – which will be used as an icon to the left of the item;
-
-
class
kivymd.uix.bottomsheet.GridBottomSheetItem¶ Bases:
kivy.uix.behaviors.ButtonBehavior,kivy.uix.boxlayout.BoxLayout-
source¶ Icon path if you use a local image or icon name if you use icon names from a file
kivymd/icon_definitions.py.sourceis anStringPropertyand defaults to ‘’.
-
caption¶ Item text.
captionis anStringPropertyand defaults to ‘’.
-
icon_size¶ Icon size.
captionis anStringPropertyand defaults to ’32sp’.
-
-
class
kivymd.uix.bottomsheet.MDGridBottomSheet(**kwargs)¶ Bases:
kivymd.uix.bottomsheet.MDBottomSheet-
add_item(self, text, callback, icon_src)¶ - Parameters
text – element text;
callback – function that will be called when clicking on an item;
icon_src – icon item;
-