SliverAppbar#
#
Added 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:
MDScreen(
MDSliverAppbar(
MDTopAppBar(
[...]
),
MDSliverAppbarHeader(
# Custom content.
[...]
),
MDSliverAppbarContent(
# Custom list.
[...]
),
)
)
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):
for x in range(10):
self.root.ids.content.add_widget(GuitarItem())
Example().run()
from kivymd.app import MDApp
from kivymd.uix.appbar import (
MDTopAppBar,
MDTopAppBarLeadingButtonContainer,
MDActionTopAppBarButton,
MDTopAppBarTitle,
MDTopAppBarTrailingButtonContainer,
)
from kivymd.uix.fitimage import FitImage
from kivymd.uix.list import (
MDListItem,
MDListItemLeadingAvatar,
MDListItemHeadlineText,
MDListItemSupportingText,
MDListItemTertiaryText,
MDListItemTrailingIcon,
)
from kivymd.uix.screen import MDScreen
from kivymd.uix.sliverappbar import (
MDSliverAppbar,
MDSliverAppbarHeader,
MDSliverAppbarContent,
)
class GuitarItem(MDListItem):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.theme_bg_color = "Custom"
self.md_bg_color = "2d4a50"
self.widgets = [
MDListItemLeadingAvatar(source="avatar.png"),
MDListItemHeadlineText(text="Ibanez"),
MDListItemSupportingText(text="GRG121DX-BKF"),
MDListItemTertiaryText(text="$445,99"),
MDListItemTrailingIcon(icon="guitar-electric"),
]
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return MDScreen(
MDSliverAppbar(
MDTopAppBar(
MDTopAppBarLeadingButtonContainer(
MDActionTopAppBarButton(
icon="arrow-left",
),
),
MDTopAppBarTitle(
text="Sliver toolbar",
),
MDTopAppBarTrailingButtonContainer(
MDActionTopAppBarButton(
icon="attachment",
),
MDActionTopAppBarButton(
icon="calendar",
),
MDActionTopAppBarButton(
icon="dots-vertical",
),
),
type="medium",
),
MDSliverAppbarHeader(
FitImage(
source="bg.jpg",
),
),
MDSliverAppbarContent(
id="content",
orientation="vertical",
padding="12dp",
theme_bg_color="Custom",
md_bg_color="2d4a50",
),
background_color="2d4a50",
hide_appbar=True,
)
)
def on_start(self):
for x in range(10):
self.root.get_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
MDBoxLayoutclass documentation.
- class kivymd.uix.sliverappbar.sliverappbar.MDSliverAppbarHeader(*args, **kwargs)#
Sliver app bar header class.
For more information, see in the
BoxLayoutclass documentation.
- class kivymd.uix.sliverappbar.sliverappbar.MDSliverAppbar(*args, **kwargs)#
Sliver appbar class.
For more information, see in the
ThemableBehaviorandBoxLayoutclasses documentation.- Events:
on_scroll_contentFired when the list of custom content is being scrolled.
- background_color#
Background color of appbar in (r, g, b, a) or string format.
background_coloris anColorPropertyand defaults to None.
- max_height#
Distance from top of screen to start of custom list content.
MDSliverAppbar: max_height: "200dp"
max_heightis anNumericPropertyand 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_appbaris anBooleanPropertyand defaults to None.
- radius#
Box radius for custom item list.
MDSliverAppbar: radius: 20
radiusis anVariableListPropertyand defaults to [20].
- max_opacity#
Maximum background transparency value for the
MDSliverAppbarHeaderclass.
MDSliverAppbar: max_opacity: .5
max_opacityis anNumericPropertyand 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 –
MDSliverAppbarvalue – see
scroll_ydirection – 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.
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)
- on__appbar(instance, value)#