python - Kivy: Top or Bottom navigation bar - Stack Overflow

For some reasons only bottom bar is shown (independently of is_mobile state). How can it be fixed?BoxL

For some reasons only bottom bar is shown (independently of is_mobile state). How can it be fixed?

BoxLayout:
    orientation: 'vertical'
    ActionBar:
        hidden: app.is_mobile
        size_hint_y: 0 if app.is_mobile else None
        ActionView:
            use_separator: True
            ActionPrevious:
                with_previous: True
                on_release: app.next_screen('main')
            ActionButton:
                text: 'Shuffle 1'
            ActionButton:
                text: 'Check'
            ActionButton:
                text: 'Next'
    Accordion:
        AccordionItem:
            title: '...'
            Label:
                text: '...'
        AccordionItem:
            title: '...'
            Label:
                text: '...'
    ActionBar:
        hidden: False if app.is_mobile else True
        size_hint_y: None if app.is_mobile else 0
        ActionView:
            use_separator: True
            ActionPrevious:
                with_previous: True
                on_release: app.next_screen('main')
            ActionButton:
                text: 'Shuffle'
            ActionButton:
                text: 'Check'
            ActionButton:
                text: 'Next'

where app_mobile is calsulated as:

from kivy.utils import platform

class MainApp(App):
    is_mobile = BooleanProperty(False)

    def build(self):
        if platform in ['android', 'ios']:
            self.is_mobile = True

For some reasons only bottom bar is shown (independently of is_mobile state). How can it be fixed?

BoxLayout:
    orientation: 'vertical'
    ActionBar:
        hidden: app.is_mobile
        size_hint_y: 0 if app.is_mobile else None
        ActionView:
            use_separator: True
            ActionPrevious:
                with_previous: True
                on_release: app.next_screen('main')
            ActionButton:
                text: 'Shuffle 1'
            ActionButton:
                text: 'Check'
            ActionButton:
                text: 'Next'
    Accordion:
        AccordionItem:
            title: '...'
            Label:
                text: '...'
        AccordionItem:
            title: '...'
            Label:
                text: '...'
    ActionBar:
        hidden: False if app.is_mobile else True
        size_hint_y: None if app.is_mobile else 0
        ActionView:
            use_separator: True
            ActionPrevious:
                with_previous: True
                on_release: app.next_screen('main')
            ActionButton:
                text: 'Shuffle'
            ActionButton:
                text: 'Check'
            ActionButton:
                text: 'Next'

where app_mobile is calsulated as:

from kivy.utils import platform

class MainApp(App):
    is_mobile = BooleanProperty(False)

    def build(self):
        if platform in ['android', 'ios']:
            self.is_mobile = True
Share Improve this question asked Jan 31 at 11:39 FieryCatFieryCat 1,89921 silver badges28 bronze badges 2
  • What do you expect to see? When is_mobile is True and when is_mobile is False. – John Anderson Commented Jan 31 at 13:41
  • is_mobile is True - bottom bar is shown, and when is_mobile is False - top bar is shown – FieryCat Commented Feb 1 at 18:00
Add a comment  | 

1 Answer 1

Reset to default 1

The ActionBar and its children ActionButton, ... have predefined sizes in the kivy style.kv file. You can get what I believe are your desired results by working with those predefined properties. Try changing your kv to:

BoxLayout:
    orientation: 'vertical'
    ActionBar:
        hidden: app.is_mobile
        # size_hint_y: 0 if app.is_mobile else None
        opacity: 1.0 if not app.is_mobile else 0
        height: '48dp' if not app.is_mobile else 0  # `480dp` is the default height from style.kv
        ActionView:
            use_separator: True
            ActionPrevious:
                with_previous: True
                on_release: app.next_screen('main')
            ActionButton:
                text: 'Shuffle 1'
            ActionButton:
                text: 'Check'
            ActionButton:
                text: 'Next'
    Accordion:
        AccordionItem:
            title: '...'
            Label:
                text: '...'
        AccordionItem:
            title: '...'
            Label:
                text: '...'
    ActionBar:
        id: ab
        hidden: False if app.is_mobile else True
        # size_hint_y: None if app.is_mobile else 0
        opacity: 1.0 if app.is_mobile else 0
        height: '48dp' if app.is_mobile else 0  # `480dp` is the default height from style.kv
        ActionView:
            use_separator: True
            ActionPrevious:
                with_previous: True
                on_release: app.next_screen('main')
            ActionButton:
                text: 'Shuffle'
            ActionButton:
                text: 'Check'
            ActionButton:
                text: 'Next'

The height property generally makes the ActionBar visible or not. The opacity property is used to make its children visible or not, because those children also have predefined sizes and will appear even if the ActionBar has zero height.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264461a4619369.html

相关推荐

  • python - Kivy: Top or Bottom navigation bar - Stack Overflow

    For some reasons only bottom bar is shown (independently of is_mobile state). How can it be fixed?BoxL

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信