在这里,我试图建立一个有导航条的应用程序,导航条上有OneLineListItem,当我点击这些项目时,屏幕会发生变化,但标签没有出现,我也尝试在布局中添加多个按钮,它工作正常,但当我添加Label时,它没有被显示。
以下是我使用的kv语言代码:---------。
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
# Menu item in the DrawerList list.
<ItemDrawer>:
theme_text_color: "Custom"
on_release: self.parent.set_color_item(self)
IconLeftWidget:
id: icon
icon: root.icon
theme_text_color: "Custom"
text_color: root.text_color
<ContentNavigationDrawer>:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
AnchorLayout:
anchor_x: "left"
size_hint_y: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "data/logo/kivy-icon-256.png"
MDLabel:
text: "Voice Cloning Tool"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: "MENU"
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
DrawerList:
OneLineListItem:
text:'Home'
on_release:app.root.current='home_screen'
OneLineListItem:
text:'Record Voice'
on_release:app.root.current='rec_screen'
OneLineListItem:
text:'Help'
OneLineListItem:
text:'About'
OneLineListItem:
text:'Contact Us'
ScreenManagement:
transition:FadeTransition()
HomeScreen:
RecordScreen:
AboutScreen:
ContactUSScreen:
<HomeScreen>:
name:'home_screen'
NavigationLayout:
ScreenManager:
Screen:
SliderWin
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Widget:
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
<RecordScreen>:
name:'rec_screen'
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Button:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
Button:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
我是个白痴,我忘了默认情况下标签是白色的,这里我的背景也是白色的,这就是它不能显示的原因,我把标签的颜色改为其他颜色,它就显示出来了。
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
# Menu item in the DrawerList list.
<ItemDrawer>:
theme_text_color: "Custom"
on_release: self.parent.set_color_item(self)
IconLeftWidget:
id: icon
icon: root.icon
theme_text_color: "Custom"
text_color: root.text_color
<ContentNavigationDrawer>:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
AnchorLayout:
anchor_x: "left"
size_hint_y: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "data/logo/kivy-icon-256.png"
MDLabel:
text: "Voice Cloning Tool"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: "MENU"
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
DrawerList:
OneLineListItem:
text:'Home'
on_release:app.root.current='home_screen'
OneLineListItem:
text:'Record Voice'
on_release:app.root.current='rec_screen'
OneLineListItem:
text:'Help'
OneLineListItem:
text:'About'
OneLineListItem:
text:'Contact Us'
ScreenManagement:
transition:FadeTransition()
HomeScreen:
RecordScreen:
AboutScreen:
ContactUSScreen:
<HomeScreen>:
name:'home_screen'
NavigationLayout:
ScreenManager:
Screen:
SliderWin
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Widget:
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
<RecordScreen>:
name:'rec_screen'
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Explore Voice cloning Tool"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.toggle_nav_drawer()]]
Label:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
color:1,0,1,1
Button:
text:'Hello World'
size_hint:0.5,0.1
pos_hint:{'x':0.5,'y':0.5}
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer