最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论