0

我想更改 ActionBar 中 ActionOverflow 内的 ActionButtons 的背景,但是使用按钮的常用方法(background_down、background_normal)似乎不起作用。

[黑色背景的ActionButton] ( https://raw.githubusercontent.com/Thomas-Adams/kivy_mananger/master/color_mananger/kivy-actionbutton.png )

奇怪的是,当我单击那个特定的 ActionButton(例如“List”)时,背景会根据需要发生变化。然而,“正常”未按下状态仍然具有黑色背景。我也尝试篡改背景图像属性,但无济于事。我想念什么?有人对此有任何线索或暗示吗?

#:import get_color_from_hex kivy.utils.get_color_from_hex
<MainView>:
    ...
                ActionButton:
                    canvas.before:
                        Color:
                            rgba: get_color_from_hex('#d500f9')
                        Rectangle:
                            size: self.size
                            pos: self.pos
                    background_normal: 'electric-violet.png'
                    background_down: 'electric-violet-lighten.png'
                    background_disabled: ''
                    background_disabled_down: ''
                    background_color: get_color_from_hex('#d500f9')
                    text: 'Create'


这是完整kv文件的链接

4

2 回答 2

0

我自己想出来了,以防其他人被困在这里,而不是使用 ActionButton 小部件,我编写了自己的基于 ActionItem 和 Button 的小部件:


class ColorActionButton(ActionItem, Button, EventDispatcher):
    color_name = StringProperty()
    base_dir = IMAGE_BASE_DIR
    b_normal = StringProperty()
    b_down = StringProperty()
    b_disabled_down = StringProperty()
    b_disabled = StringProperty()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def on_color_name(self, instance, value):
        self.b_normal = self.base_dir + value + SUFFIX
        self.b_down = self.base_dir + value + LIGHTEN_SUFFIX
        self.b_disabled_down = self.base_dir + value + DARKEN_SUFFIX

现在使用它就像一个魅力。

于 2019-09-01T14:41:02.410 回答
0

另一种可能性是根据以下内容创建自己的类ActionButton

class MyActionButton(ActionButton):
    real_background_normal = StringProperty('')

kv并在您的文件中修改其样式:

<MyActionButton>:
    -background_normal: self.real_background_normal

然后在kv文件的其他地方,当您使用 时MyActionButton,只需使用real_background_normal而不是background_normal

MyActionButton:
    real_background_normal: 'electric-violet.png'
于 2019-09-01T15:27:39.740 回答