KivyMD
KivyMD copied to clipboard
MDNavigationRail Active
Description of the Bug
When the active
property from a MDNavigationRailItem is set from the code, the navigation rail don't set this to active and the hover not works anymore.
Code and Logs
I picked up this code from the navigation rail documentation, only change the active from the first Item to True.
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.app import MDApp
from kivymd.uix.navigationrail import MDNavigationRailItem
KV = '''
<CommonNavigationRailItem>
MDNavigationRailItemIcon:
icon: root.icon
MDNavigationRailItemLabel:
text: root.text
MDBoxLayout:
MDNavigationRail:
type: "selected"
MDNavigationRailMenuButton:
icon: "menu"
MDNavigationRailFabButton:
icon: "home"
CommonNavigationRailItem:
id: first
active: True
icon: "folder-outline"
text: "Files"
CommonNavigationRailItem:
icon: "bookmark-outline"
text: "Bookmark"
CommonNavigationRailItem:
icon: "library-outline"
text: "Library"
MDScreen:
md_bg_color: self.theme_cls.secondaryContainerColor
'''
class CommonNavigationRailItem(MDNavigationRailItem):
text = StringProperty()
icon = StringProperty()
class Example(MDApp):
def build(self):
build = Builder.load_string(KV)
# Or when do this too:
# build.ids.first.active = True
return build
Example().run()
Screenshots
Versions
- OS: Windows 10
- Python: 3.12
- Kivy: 2.3.0
- KivyMD: master