我想更改MDToolbar left_action_item图标的颜色。它的默认值为白色,但现在我想将其更改为红色。最简单的方法是什么?我已经尝试了几乎所有内容(text_color,bg_color等)都无济于事。
答案 0 :(得分:1)
您无法更改工具栏中图标的颜色。
答案 1 :(得分:0)
使用specific_text_color: 1,0,1,1
可以更改工具栏内文本的颜色。它将同时更改文本和图标。我不知道如何仅更改图标。也许有帮助。
目前,我无法更改OneLineIconListItem
的图标颜色。我认为与我们遇到的约束相同吗?
答案 2 :(得分:0)
在这种情况下,我建议在KivyMD repository中搜索相关的窗口小部件类,然后四处浏览以查看其定义方式,相关的ID等。例如,this line中的toolbar.py似乎在工具栏中定义了图标:
def update_action_bar(self, action_bar, action_bar_items):
#...
action_bar.add_widget(
MDIconButton(
icon=item[0],
on_release=item[1],
opposite_colors=True,
text_color=self.specific_text_color,
theme_text_color="Custom",
)
)
#...
在这里,我们了解到工具栏的图标属于MDIconButton
类,并且它们具有text_color
颜色属性,似乎可以设置颜色。
从where the function above is called看,我们看到这些图标分别作为小部件添加到self.ids["left_actions"]
和self.ids["right_actions"]
:
def on_left_action_items(self, instance, value):
self.update_action_bar(self.ids["left_actions"], value)
def on_right_action_items(self, instance, value):
self.update_action_bar(self.ids["right_actions"], value)
现在,在我们自己的代码中(例如在我们的build()
的{{1}}函数中知道了所有这些内容),我们就可以访问和修改属性:
MainApp
这不需要在build()中,它只需要放在可以通过其ID通过某种方式访问工具栏小部件的位置即可。
答案 3 :(得分:0)
同时使用 md_bg_color: app.theme_cls.primary_color 和 text_color: rgba('#F0F0F0') 允许我更改 MDToolbar 中图标按钮的颜色。 >