首页 > 解决方案 > 在 Kivy ActionBar 的 ActionOverFlow 区域中未显示 ActionButton 图标

问题描述

我在操作栏中设置了一些按钮并将图像用作图标。当应用程序窗口最大化时,按钮会显示,但当应用程序窗口调整大小(变小)时,它们在溢出区域中不可见。我只看到空白的黑框。你能帮忙吗?

基维代码:

<SivaStatusScreen>:
    name: 'status_screen'
    canvas.before:
        Color:
            rgba: 255/255, 255/255, 255/255, 1
        Rectangle:
            pos: self.pos
            size: self.size
    BoxLayout:
        id: status_layout
        size_hint: 1, 1
        orientation: 'vertical'
        BoxLayout:
            id: actionbar_layout
            size_hint: 1, 0.1
            ActionBar:
                id: status_actionbar
                pos_hint: {'top': 1}
                background_image: ''
                background_color: 195/255, 60/255, 35/255, 1
                ActionView:
                    use_separator: True
                    ActionPrevious:
                        title: 'S.I.V.A'
                        with_previous: False
                    ActionOverflow:
                    ActionButton:
                        important: True
                        icon: 'images/communication-96.png'
                    ActionButton:
                        important: True
                        icon: 'images/key-96.png'
                    ActionButton:
                        important: True
                        icon: 'images/services-96.png'
                    ActionButton:
                        important: True
                        icon: 'images/shutdown-96.png'
        BoxLayout:
            id: status_display
            size_hint: 1, 0.9
    AnchorLayout:
        id: status_add
        anchor_x: 'right'
        anchor_y: 'bottom'
        ImageButton:
            id: status_addbtn
            source: {'normal': 'images/plus-96.png', 'down': 'images/plusblue-96.png'} [self.state]
            size_hint: 0.2, 0.2

当窗口最大化时,按钮图标可见。当窗口最小化时,按钮图标在操作溢出区域中不可见。但是,按钮和文本按钮的文本标签确实可以正确显示。难道是下拉菜单的大小限制了图标的显示?

请帮忙。

提前致谢。

标签: kivykivy-language

解决方案


Python 方面的一些变化(定义了一些新的自定义类):

class ImageButton(ButtonBehavior, Image):
    pass


class CustomActionButton(ImageButton, ActionItem):
    pass

Kivy 方面的一些变化:

<CustomActionButton>:
    size_hint_x: 0.05
    size_hint_min_x: 48

设置小部件沿 x 轴的宽度和图标的最小像素宽度就可以了。这些按钮现在按预期工作。


推荐阅读