无法在KivyMD中更改标签文本和图标的颜色

时间:2020-07-29 13:22:14

标签: tabs kivy-language kivymd

我正在尝试学习如何使用KivyMD进行编程。经过研究并观看了一些教程之后,我将GUI与跟踪和错误方法结合在一起。

目前,我正在尝试更改“标签”文本和图标的颜色。经过数小时的在线搜索,iam仍然无法更改它们。 .kv文件中的text_color_normal:text_color_active: 似乎对他们没有影响。我感觉我在这里做一些根本错误的事情。有人可以给我一些如何进行的提示吗? Main.py和.KV文件在下面。

谢谢!

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.tab import MDTabsBase
from kivymd.font_definitions import fonts
from kivymd.icon_definitions import md_icons
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget


Window.size = (300, 500) # voor develop doeleinden mobielscherm


class Screen1(Screen):
    pass


class Screen2(Screen):
    pass


class Screen3(Screen):
    pass


class Screen4(Screen):
    pass


class Tab(FloatLayout, MDTabsBase):
    pass


class Tab1(FloatLayout, MDTabsBase):
    pass


class DemoApp(MDApp):

    def build(self):

        self.theme_cls.primary_palette = 'Red'
        screen = Builder.load_file('demo_file.kv')

        return screen

    def navigation_draw(self):
        print('navigation')


DemoApp().run()

demo_file.kv

Screen:
    NavigationLayout:

        ScreenManager:
            id:screen_manager

            Screen1:
                name: 'home_screen'

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: 'Home'
                        left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
                        elevation: 0
                        specific_text_color: 0,0,0,1

                    MDTabs:
                        id:android_tabs
                        tab_bar_height: '35dp'
                        background_color: 1,0,0,0.85
                        elevation: 0
                        text_color_normal: 0, 1, 0, 1
                        text_color_active: 1, 0, 0, 1
                        color_indicator: 0.95, 0.95, 0.1, 1

                        Tab:
                            text: 'Tab1'

                        Tab1:
                            text: 'chart-pie'

                    MDBottomAppBar:

                        MDToolbar:
                            title: 'Start sessie'
                            mode: 'end'
                            type: 'bottom'
                            on_action_button: app.navigation_draw()
                            icon: 'beer'
                            icon_color: 0.95, 0.95, 0.1, 1

            Screen2:
                name: 'profile_screen'

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: 'Profiel'
                        left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
                        elevation: 7
                    Widget:

            Screen3:
                name: 'session_screen'

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: 'Sessies'
                        left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
                        elevation: 10
                    Widget:


            Screen4:
                name: 'logout_screen'

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: 'Uitloggen'
                        left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]
                        elevation: 10
                    Widget:

        MDNavigationDrawer:
            id:nav_drawer

            BoxLayout:
                orientation: 'vertical'
                spacing: '8dp'
                padding: '8dp'

                Image:
                    source: 'avatar.jpg'

                MDLabel:
                    text: '     Name'
                    front_style: 'Subtitle1'
                    size_hint_y: None
                    height: self.texture_size[1]

                MDLabel:
                    text: '     email@hotmail.com'
                    front_style: 'Caption'
                    size_hint_y: None
                    height: self.texture_size[1]

                ScrollView:
                    MDList:
                        OneLineIconListItem:
                            text: 'Profiel'
                            on_press: screen_manager.current = 'profile_screen'
                            IconLeftWidget:
                                icon: 'face-profile'
                                on_press: screen_manager.current = 'profile_screen'


                        OneLineIconListItem:
                            text: 'Drink sessies'
                            on_press: screen_manager.current = 'session_screen'
                            IconLeftWidget:
                                icon: 'beer'
                                on_press: screen_manager.current = 'session_screen'

                        OneLineIconListItem:
                            text: 'Uitloggen'
                            on_press: screen_manager.current = 'logout_screen'
                            IconLeftWidget:
                                icon: 'logout'
                                on_press: screen_manager.current = 'logout_screen'

<Tab>:

    MDLabel:

        text:'tab1'
        user_font_size: "48sp"
        pos_hint: {"center_x": .5, "center_y": .5}

<Tab1>:

    MDLabel:

        text:'tab2'
        user_font_size: "48sp"
        pos_hint: {"center_x": .5, "center_y": .5}

3 个答案:

答案 0 :(得分:0)

更改选项卡文本/图标的颜色?那对我有用。

也许尝试重新安装KivyMD。

答案 1 :(得分:0)

我终于弄清楚了为什么我的代码无法正常工作。在搜索网络时,我偶然发现了更改日志,并且发现未发布的版本包含针对text_color_normaltext_color_active的修复程序。这意味着在我当前的版本(0.104.1)中,参数无法正常工作。对我来说,使用pip install https://github.com/kivymd/KivyMD/archive/master.zip安装KivyMD可以。

感谢您为解决此问题付出的努力!

答案 2 :(得分:0)

相反测试:text_color : rgba(253, 0, 253,255) 对我有用