Snackbar#
See also Snackbars provide brief messages about app processes at the bottom
of the screen. On mobile, use up to two lines of text to communicate the snackbar message: text=”First string”, ),
MDSnackbarActionButton( text=”Done”,
theme_text_color=”Custom”,
text_color=”#8E353C”, ),
y=dp(24),
pos_hint={“center_x”: 0.5},
size_hint_x=0.5,
md_bg_color=”#E8D8D7”, ).open()
Usage#
MDSnackbar(
MDLabel(
text="First string",
theme_text_color="Custom",
text_color="#393231",
),
).open()
Example#
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.snackbar import MDSnackbar
KV = '''
MDScreen:
MDRaisedButton:
text: "Create simple snackbar"
on_release: app.open_snackbar()
pos_hint: {"center_x": .5, "center_y": .5}
'''
class Example(MDApp):
def open_snackbar(self):
MDSnackbar(
MDLabel(
text="First string",
),
).open()
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_string(KV)
Example().run()
Control width and pos#
MDSnackbar(
MDLabel(
text="First string",
),
pos=(dp(24), dp(56)),
size_hint_x=0.5,
).open()
MDSnackbar(
MDLabel(
text="First string",
theme_text_color="Custom",
text_color="#393231",
),
MDLabel(
text="Second string",
theme_text_color="Custom",
text_color="#393231",
),
y=dp(24),
pos_hint={"center_x": 0.5},
size_hint_x=0.5,
md_bg_color="#E8D8D7",
).open()
API break#
1.1.1 version#
snackbar = Snackbar(
text="First string",
snackbar_x="10dp",
snackbar_y="24dp",
)
snackbar.size_hint_x = (
Window.width - (snackbar.snackbar_x * 2)
) / Window.width
snackbar.buttons = [
MDFlatButton(
text="Done",
theme_text_color="Custom",
text_color="#8E353C",
on_release=snackbar.dismiss,
),
]
snackbar.open()
1.2.0 version#
API - kivymd.uix.snackbar.snackbar
#
- class kivymd.uix.snackbar.snackbar.MDSnackbarCloseButton(*args, **kwargs)#
Snackbar closed button class.
For more information, see in the
MDIconButton
class documentation.
- class kivymd.uix.snackbar.snackbar.MDSnackbarActionButton(*args, **kwargs)#
Snackbar action button class.
For more information, see in the
MDFlatButton
class documentation.
- class kivymd.uix.snackbar.snackbar.MDSnackbar(*args, **kwargs)#
Snackbar class.
Changed in version 1.2.0: Rename BaseSnackbar to MDSnackbar class.
For more information, see in the
MDCard
andStencilBehavior
class documentation.- Events:
on_open
Called when a snackbar opened.
on_dismiss
Called when a snackbar closes.
- show_transition#
The type of transition of the snackbar opening.
New in version 1.2.0.
show_transition
is aStringProperty
and defaults to ‘linear’.
- show_duration#
Duration of snackbar display transition.
New in version 1.2.0.
show_duration
is aNumericProperty
and defaults to 0.2.
- hide_transition#
The type of transition of the snackbar closing.
New in version 1.2.0.
hide_transition
is aStringProperty
and defaults to ‘linear’.
- hide_duration#
Duration of snackbar closing transition.
New in version 1.2.0.
hide_duration
is aNumericProperty
and defaults to 0.2.
- duration#
The amount of time that the snackbar will stay on screen for.
duration
is aNumericProperty
and defaults to 3.
- auto_dismiss#
Whether to use automatic closing of the snackbar or not.
auto_dismiss
is aBooleanProperty
and defaults to True.
- radius#
Snackbar radius.
radius
is aListProperty
and defaults to [5, 5, 5, 5]
- bg_color#
Snackbar background color in (r, g, b, a) or string format.
Deprecated since version 1.2.0: Use ‘md_bg_color` instead.
bg_color
is aColorProperty
and defaults to None.
- buttons#
Snackbar buttons.
Deprecated since version 1.2.0.
buttons
is aListProperty
and defaults to []
- snackbar_animation_dir#
Snackbar animation direction. Available options are: ‘Top’, ‘Bottom’, ‘Left’, ‘Right’.
Deprecated since version 1.2.0.
snackbar_animation_dir
is anOptionProperty
and defaults to ‘Bottom’.
- snackbar_x#
The snackbar x position in the screen
Deprecated since version 1.2.0.
snackbar_x
is aNumericProperty
and defaults to 0.
- snackbar_y#
The snackbar x position in the screen
Deprecated since version 1.2.0.
snackbar_y
is aNumericProperty
and defaults to 0.
- dismiss(self, *args)#
Dismiss the snackbar.
- open(self)#
Show the snackbar.
- add_widget(self, widget, *args, **kwargs)#
Add a new widget as a child of this widget.
- Parameters:
- widget:
Widget
Widget to add to our list of children.
- index: int, defaults to 0
Index to insert the widget in the list. Notice that the default of 0 means the widget is inserted at the beginning of the list and will thus be drawn on top of other sibling widgets. For a full discussion of the index and widget hierarchy, please see the Widgets Programming Guide.
New in version 1.0.5.
- canvas: str, defaults to None
Canvas to add widget’s canvas to. Can be ‘before’, ‘after’ or None for the default canvas.
New in version 1.9.0.
- widget:
>>> from kivy.uix.button import Button >>> from kivy.uix.slider import Slider >>> root = Widget() >>> root.add_widget(Button()) >>> slider = Slider() >>> root.add_widget(slider)
- on_open(self, *args)#
Called when a snackbar opened.
- on_dismiss(self, *args)#
Called when a snackbar closed.