无法直接关闭ActionOverflow

时间:2016-11-05 11:51:13

标签: python-2.7 kivy

我的应用程序(ScreenManager)中有2个Screens。其中一人ActionBar ActionOverflow。我有一个按钮,可以更改当前Screen并关闭ActionOverflow,但Screen更改和ActionOverflow保持打开状态,直到 我在另一个地方点击屏幕。

这里有一些代码:

# .kv
ScreenManager:
    id: ScrMan
    Screen:
        name: 'scr1'
        BoxLayout:
            orientation: 'vertical'
            ActionBar:
                ActionView:
                    ActionOverflow:
                        id: ActOv
                        #some buttons
                        ActionButton:
                            text: 'some text'
                            on_press: 
                                ActOv.is_open = False
                                #I also tried: is_open = False; self.parent.is_open = False; with the same result
                                ScrMan.current = 'scr2'

    Screen:
        name: 'scr2'
        #some cool stuff here

如何更改屏幕并关闭ActionOverflow列表?

1 个答案:

答案 0 :(得分:1)

编辑:由于您拥有版本1.9.1(或较旧的主分支,但缺少this修复程序。在actionbar.py中更改<python dir>/Lib/site-packages/kivy/uix/actionbar.py会将默认行为带入旧版本。< / p>

默认情况下,下拉列表应自行关闭。也许你的代码有问题,例如将ActionButton作为小部件或其他内容放入ActionOverflow。试试这个:

from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
#:import Clock kivy.clock.Clock
#:import partial functools.partial
<Test>:
    ScreenManager:
        id: ScrMan
        Screen:
            name: 'scr1'
            ActionBar:
                pos_hint: {'top': 1}
                ActionView:
                    ActionPrevious:
                    ActionOverflow:
                    ActionButton:
                        text: 'some very very long text'
                    ActionButton:
                        text: 'some very very long text'
                    ActionButton:
                        text: 'some very very long text'
                    ActionButton:
                        text: 'some very very long text'
                    ActionButton:
                        text: 'some very very long text'
                    ActionButton:
                        text: 'try this button!'
                        on_press: 
                            ScrMan.current = 'scr2'
                            Clock.schedule_once(partial(root.change_scr, ScrMan), 1)
        Screen:
            name: 'scr2'
            Label:
                text: 'second'
''')
class Test(BoxLayout):
    def change_scr(self, man, *dt):
        man.current = man.previous()
runTouchApp(Test())