这是一个完整的应用程序,虽然很简短:
main.py
:
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.clock import Clock
from kivymd.app import MDApp
from kivymd.uix.tab import MDTabsBase
from kivymd.uix.list import OneLineListItem
from kivymd.icon_definitions import md_icons
class TabList(FloatLayout, MDTabsBase):
"""The engaged power supplies tab."""
def surfacing(self, tab_text):
pass
def discover(self):
for i in range(30):
self.ids.container.add_widget(
OneLineListItem(text=f"Power supply {i + 1:>4}")
)
class TabDetails(FloatLayout, MDTabsBase):
"""The engaged power supply details tab."""
def surfacing(self, tab_text):
self.ids.icon.icon = "equalizer"
class Contero(MDApp):
def build(self):
return Builder.load_file("main.kv")
def on_start(self):
text = "flash"
main = TabList(text=text)
main.surfacing(text)
self.root.ids.android_tabs.add_widget(main)
Clock.schedule_once(lambda dt: main.discover(), 2)
self.root.ids.android_tabs.add_widget(TabDetails(text="equalizer"))
def on_tab_switch(self, instance_tabs, instance_tab, instance_tab_label, tab_text):
"""Called when switching tabs.
:type instance_tabs: <kivymd.uix.tab.MDTabs object>;
:param instance_tab: <__main__.Tab object>;
:param instance_tab_label: <kivymd.uix.tab.MDTabsLabel object>;
:param tab_text: text or name icon of tab;
"""
instance_tab.surfacing(tab_text)
Contero().run()
main.kv
:
BoxLayout:
orientation: "vertical"
#MDToolbar:
# title: "Example Tabs"
MDTabs:
id: android_tabs
on_tab_switch: app.on_tab_switch(*args)
<TabList>:
ScrollView:
bar_margin: 5
bar_width: 15
bar_color: .0, .8, .0, 1
bar_inactive_color: .5, .5, .5, 1
effect_cls: "ScrollEffect"
scroll_type: ["bars", "content"]
scroll_distance: 5
scroll_timeout: 250
MDList:
id: container
<TabDetails>:
MDIconButton:
id: icon
user_font_size: "48sp"
pos_hint: {"center_x": .5, "center_y": .5}
我想在列表选项卡中选择一个列表项,然后跳到“详细信息”选项卡。通过 press (或双击作为备用)进行选择,以编程方式跳转(通过在“详细信息”(右侧)选项卡上生成适当的 tap 事件,如果那是正确的方法)。不幸的是,我什至无法猜测应该如何区分 tap , press 和双击。从视觉效果来看,MDList
知道其中的一些区别。