SliverAppbar#

#

New in version 1.0.0.

MDSliverAppbar is a Material Design widget in KivyMD which gives scrollable or collapsible MDTopAppBar

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-appbar-preview.gif

Note

This widget is a modification of the silverappbar.py module.

Usage#

MDScreen:

    MDSliverAppbar:

        MDTopAppBar:
            [...]

        MDSliverAppbarHeader:

            # Custom content.
            [...]

        # Custom list.
        MDSliverAppbarContent:

Anatomy#

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-appbar-anatomy.png

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 and BoxLayout 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 an ColorProperty and defaults to None.

max_height#

Distance from top of screen to start of custom list content.

MDSliverAppbar:
    max_height: "200dp"
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-appbar-max-height.png

max_height is an NumericProperty 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
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-appbar-hide-appbar-false.gif
MDSliverAppbar:
    hide_appbar: True
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-appbar-hide-appbar-true.gif

hide_appbar is an BooleanProperty and defaults to None.

radius#

Box radius for custom item list.

MDSliverAppbar:
    radius: 20
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-app-bar-radius.png

radius is an VariableListProperty and defaults to [20].

max_opacity#

Maximum background transparency value for the MDSliverAppbarHeader class.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-app-bar-max-opacity.gif
MDSliverAppbar:
    max_opacity: .5
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/sliver-app-bar-max-opacity-05.gif

max_opacity is an NumericProperty and defaults to 1.

on_hide_appbar(instance, value) None#

Fired when the hide_appbar value changes.

on_scroll_content(instance: object = None, value: float = 1.0, direction: str = 'up')#

Fired when the list of custom content is being scrolled.

Parameters:
on_background_color(instance, color) None#

Fired when the background_color value changes.

on_vbar() None#
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.

>>> 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)#