如何根据显示的MDBottomNavigationItem更改MDToolbar的标题

问题描述 投票:0回答:1

我正在使用KivyMD开发应用程序(至少正在尝试)。要导航,我想使用MDBottomNavigation。我的问题是我还想用MDToolbar显示标题,该标题“链接”到显示的内容。我的.kv文件如下所示:

BoxLayout:
    orientation: 'vertical'
    id: blayout

    MDToolbar:
        title: "1" if... else "2"

    MDBottomNavigation:
        id: navigation

        MDBottomNavigationItem:
            text: "xxx"

        MDBottomNavigationItem:
            text: "yyy"

我只是不知道该在其他之间插入什么,我想我必须检查显示的选项卡(使用id吗?),但我不知道该怎么做,也找不到任何线索。

python kivy kivy-language
1个回答
0
投票

这就是这样做的方式:

BoxLayout:
    orientation: 'vertical'
    id: blayout

    MDToolbar:
        id: toolbar
        title: "1"

    MDBottomNavigation:
        id: navigation

        MDBottomNavigationItem:
            text: "xxx"

            on_tab_release: toolbar.title = "1"

        MDBottomNavigationItem:
            text: "yyy"

            on_tab_release: toolbar.title = "2"
© www.soinside.com 2019 - 2024. All rights reserved.