SliverAppbar#
#
New in version 1.0.0.
MDSliverAppbar is a Material Design widget in KivyMD which gives scrollable or collapsible MDTopAppBar
Note
This widget is a modification of the silverappbar.py module.
Usage#
MDScreen:
MDSliverAppbar:
MDTopAppBar:
[...]
MDSliverAppbarHeader:
# Custom content.
[...]
# Custom list.
MDSliverAppbarContent:
Anatomy#
Example#
from kivy.lang.builder import Builder
from kivymd.app import MDApp
from kivymd.uix.list import MDListItem
KV = '''
<GuitarItem>
theme_bg_color: "Custom"
md_bg_color: "2d4a50"
MDListItemLeadingAvatar
source: "avatar.png"
MDListItemHeadlineText:
text: "Ibanez"
MDListItemSupportingText:
text: "GRG121DX-BKF"
MDListItemTertiaryText:
text: "$445,99"
MDListItemTrailingIcon:
icon: "guitar-electric"
MDScreen:
MDSliverAppbar:
background_color: "2d4a50"
hide_appbar: True
MDTopAppBar:
type: "medium"
MDTopAppBarLeadingButtonContainer:
MDActionTopAppBarButton:
icon: "arrow-left"
MDTopAppBarTitle:
text: "Sliver toolbar"
MDTopAppBarTrailingButtonContainer:
MDActionTopAppBarButton:
icon: "attachment"
MDActionTopAppBarButton:
icon: "calendar"
MDActionTopAppBarButton:
icon: "dots-vertical"
MDSliverAppbarHeader:
FitImage:
source: "bg.jpg"
MDSliverAppbarContent:
id: content
orientation: "vertical"
padding: "12dp"
theme_bg_color: "Custom"
md_bg_color: "2d4a50"
'''
class GuitarItem(MDListItem):
...
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return Builder.load_string(KV)
def on_start(self):
super().on_start()
for x in range(10):
self.root.ids.content.add_widget(GuitarItem())
Example().run()
API break#
1.2.0 version#
#:import SliverToolbar __main__.SliverToolbar
Root:
MDSliverAppbar:
[...]
MDSliverAppbarHeader:
[...]
MDSliverAppbarContent:
[...]
class SliverToolbar(MDTopAppBar):
[...]
2.0.0 version#
Root:
MDSliverAppbar:
[...]
MDTopAppBar:
[...]
MDSliverAppbarHeader:
[...]
MDSliverAppbarContent:
[...]
API - kivymd.uix.sliverappbar.sliverappbar
#
- class kivymd.uix.sliverappbar.sliverappbar.MDSliverAppbarContent(*args, **kwargs)#
Implements a box for a scrollable list of custom items.
For more information, see in the
MDBoxLayout
class documentation.
- class kivymd.uix.sliverappbar.sliverappbar.MDSliverAppbarHeader(**kwargs)#
Sliver app bar header class.
For more information, see in the
BoxLayout
class documentation.
- class kivymd.uix.sliverappbar.sliverappbar.MDSliverAppbar(**kwargs)#
Sliver appbar class.
For more information, see in the
ThemableBehavior
andBoxLayout
classes documentation.- Events:
on_scroll_content
Fired when the list of custom content is being scrolled.
- background_color#
Background color of appbar in (r, g, b, a) or string format.
background_color
is anColorProperty
and defaults to None.
- max_height#
Distance from top of screen to start of custom list content.
MDSliverAppbar: max_height: "200dp"
max_height
is anNumericProperty
and defaults to Window.height / 2.
- hide_appbar#
Whether to hide the appbar when scrolling through a list of custom content.
Changed in version 2.0.0: Rename hide_toolbar to hide_appbar attribute.
MDSliverAppbar: hide_appbar: False
MDSliverAppbar: hide_appbar: True
hide_appbar
is anBooleanProperty
and defaults to None.
- radius#
Box radius for custom item list.
MDSliverAppbar: radius: 20
radius
is anVariableListProperty
and defaults to [20].
- max_opacity#
Maximum background transparency value for the
MDSliverAppbarHeader
class.MDSliverAppbar: max_opacity: .5
max_opacity
is anNumericProperty
and defaults to 1.
- on_scroll_content(instance: object = None, value: float = 1.0, direction: str = 'up')#
Fired when the list of custom content is being scrolled.
- Parameters:
instance –
MDSliverAppbar
value – see
scroll_y
direction – scroll direction: ‘up/down’
- add_widget(widget, index=0, canvas=None)#
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__appbar(instance, value)#