Snackbar#
#
See also
Snackbars provide brief messages about app processes at the bottom of the screen.
Snackbars shouldn’t interrupt the user’s experience
Usually appear at the bottom of the UI
Can disappear on their own or remain on screen until the user takes action
Usage#
MDSnackbar(
MDSnackbarText(
text="Text",
),
y=dp(24),
pos_hint={"center_x": 0.5},
size_hint_x=0.5,
).open()
Container
Supporting text
Action (optional)
Icon (optional close affordance)
Anatomy#
Configurations#
1. Single line#
MDSnackbar(
MDSnackbarText(
text="Single-line snackbar",
),
y=dp(24),
pos_hint={"center_x": 0.5},
size_hint_x=0.5,
).open()
2. Single-line snackbar with action#
MDSnackbar(
MDSnackbarSupportingText(
text="Single-line snackbar with action",
),
MDSnackbarButtonContainer(
MDSnackbarActionButton(
MDSnackbarActionButtonText(
text="Action button"
),
),
pos_hint={"center_y": 0.5}
),
y=dp(24),
orientation="horizontal",
pos_hint={"center_x": 0.5},
size_hint_x=0.5,
).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#
MDSnackbar(
MDLabel(
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()
2.0.0 version#
MDSnackbar(
MDSnackbarSupportingText(
text="Single-line snackbar with action",
),
MDSnackbarButtonContainer(
MDSnackbarActionButton(
MDSnackbarActionButtonText(
text="Action button"
),
),
pos_hint={"center_y": 0.5}
),
y=dp(24),
orientation="horizontal",
pos_hint={"center_x": 0.5},
size_hint_x=0.5,
background_color=self.theme_cls.onPrimaryContainerColor,
).open()
API - kivymd.uix.snackbar.snackbar
#
- class kivymd.uix.snackbar.snackbar.MDSnackbarButtonContainer(*args, **kwargs)#
The class implements a container for placing snackbar buttons.
For more information, see in the
DeclarativeBehavior
andBoxLayout
classes documentation.- add_widget(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.
Added 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.
Added 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)
- class kivymd.uix.snackbar.snackbar.MDSnackbarCloseButton(**kwargs)#
Snackbar closed button class.
For more information, see in the
MDIconButton
class documentation.
- class kivymd.uix.snackbar.snackbar.MDSnackbarActionButtonText(*args, **kwargs)#
The class implements the text for the
MDSnackbarActionButton
class.Changed in version 2.2.0.
For more information, see in the
MDButtonText
class documentation.
- class kivymd.uix.snackbar.snackbar.MDSnackbarActionButton(*args, **kwargs)#
Snackbar action button class.
For more information, see in the
MDButton
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
MotionShackBehavior
andMDCard
and class documentation.- Events:
on_open
Fired when a snackbar opened.
on_dismiss
Fired when a snackbar closes.
- 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 [dp(4), dp(4), dp(4), dp(4)]
- background_color#
The background color in (r, g, b, a) or string format of the snackbar.
background_color
is aColorProperty
and defaults to None.
- add_widget(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.
Added 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.
Added 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)