删除Action Bar Icon Kivy

时间:2016-05-26 11:10:46

标签: python android-actionbar kivy

我正在使用kivy

中的操作栏上面的代码



ActionBar:
		background_color:0,191,255,0.5
		pos_hint: {'top':1}
		
		ActionView:
			ActionPrevious:
				with_previous: False
				text:"    [b]Dhobiwala.com[/b]"
				
				app_icon:""
                ### I make app_icon as a blank string...but it takes default icon...I totally want to remove icon from my action bar

				markup:True
				font_size:"16dp"
				on_release:root.Show_Devlopers_Info()
				




按照上面的代码...我想从状态栏中删除图标....我甚至在Kivy的文档中找不到任何内容......任何人都有一些想法?

5 个答案:

答案 0 :(得分:2)

看起来禁用图标是不可能的 参考:Kivy来源@ github(https://github.com/kivy/kivy/blob/856b305c0c876e53e802f1ac9ae16c21fa91ac1e/kivy/uix/actionbar.py#L214) 相关部分:

if not self.app_icon:
        self.app_icon = 'data/logo/kivy-icon-32.png'

您可以尝试使用一个小的完全透明的图像作为图标来规避这一点。

此外,您可以尝试将图标的大小缩小为0.查看属性app_icon_widthapp_icon_heighthttps://kivy.org/docs/api-kivy.uix.actionbar.html#kivy.uix.actionbar.ActionPrevious.app_icon_height

答案 1 :(得分:1)

它是一个黑客,但由于kivy.uix.actionbar.ActionPrevious实际上是BoxLayout的子类,您实际上可以使用remove_widget()clear_widgets()之类的方法来操纵其内容创造它:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

kv = """
<MyWidget>:
    ap: ap
    ActionBar:
        background_color:0,191,255,0.5
        pos_hint: {'top':1}

        ActionView:
            ActionPrevious:
                id: ap
                with_previous: False
                text:"    [b]Dhobiwala.com[/b]"

                markup:True
                font_size:"16dp"
"""

Builder.load_string(kv)

class MyWidget(BoxLayout):
    def __init__(self, *args):
        super(MyWidget, self).__init__(*args)
        self.ap.clear_widgets()

class MyButtonsApp(App):
    def build(self):
        return MyWidget()

if __name__ == '__main__':
    MyButtonsApp().run()

答案 2 :(得分:1)

请阅读代码内注释,以便 Frankenstein 隐藏ActionPrevious各个方面的首选方法;当我在DropDown上尝试时,删除它似乎不是一个选项而Kivy v1.10.0 没有欢乐,但是一个人能够隐藏部分或整个事物从视图。

#!/usr/bin/env python

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout

## Un-comment if you wish to add to the action view via Python
# from kivy.uix.actionbar import ActionButton, ActionGroup

kv = """
<SomeLayout_GridLayout>:
    cols: 1
    rows: 2
    row_force_default: True
    rows_minimum: {0: ActionBar.height, 1: self.height - ActionBar.height}
    SomeMenu_ActionBar:
        id: ActionBar

<SomeMenu_ActionBar@ActionBar>:
    ActionView:
        id: ActionView
        ## Choose one of the following three pre-coded options
        HiddenIcon_ActionPrevious:
        # HiddenText_ActionPrevious:
        # Hidden_ActionPrevious:

        ## Do the ActionGroup(s) with ActionButton(s) within thing
        ActionGroup:
            id: App_ActionGroup
            mode: 'spinner'
            text: 'App'
            ActionButton:
                text: 'Settings'
                on_press: app.open_settings()
            ActionButton:
                text: 'Quit'
                on_press: app.get_running_app().stop()

        ActionGroup:
            id: File_ActionGroup
            mode: 'spinner'
            text: 'File'
            ActionButton:
                text: 'Open'
            ActionButton:
                text: 'Save'

## Inspired by: https://stackoverflow.com/a/36201399/2632107
##  Hide just the icon, but keep the text, note though
##  that one will lose the 'on_press' and similar methods
<HiddenIcon_ActionPrevious@ActionPrevious>:
    title: app.title if app.title is not None else 'Action Previous'
    with_previous: False
    app_icon: ''
    app_icon_width: 0
    app_icon_height: 0
    ## Comment out the following two lines if you wish to have
    ##  ActionGroup(s) and or ActionButtion(s) pushed to the right
    size_hint_x: None
    width: len(self.title) * 10

## Keep the icon and UI methods but hide the text
<HiddenText_ActionPrevious@ActionPrevious>: #
    with_previous: False
    on_press: print(self)
    title: ''

## Hide everything
<Hidden_ActionPrevious@ActionPrevious>:
    with_previous: False
    on_press: print(self) ## method that will not be called easily
    title: '' ## Try placing text here, only a few pixels should show
    size_hint: None, None
    size: 0, 0
"""


class SomeLayout_GridLayout(GridLayout):
    pass


class SomeApp(App):
    def build(self):
        ## Cannot set this in '__init__' for some reason
        self.title = 'Some Sweet App'

        Builder.load_string(kv)

        some_layout = SomeLayout_GridLayout()
        ## Uncomment next line if ya wish to use 'add_widget'
        ##  method on ActionView and add ActionGroup(s) and/or
        ##  ActionButton(s) via Python
        # some_actionview = some_layout.ids.ActionBar.ids.ActionView
        return some_layout

if __name__ == '__main__':
    SomeApp().run()

答案 3 :(得分:0)

ActionPrevious:
   title: 'Recently Available'
   with_previous: False
   app_icon: '' if self.app_icon is not None else "assets/images/P1.png"

答案 4 :(得分:0)

基维 2.0.0

要轻松删除 ActionBar 中的徽标,只需将其 ActionPrevious 子项设置为空字符串。

ActionPrevious:
    title: 'Title'
    with_previous: False
    app_icon: '' 

以这个脚本为例

from kivy.base import runTouchApp
from kivy.lang import Builder

runTouchApp(Builder.load_string('''
ActionBar:
    pos_hint: { 'top': 1 }
    background_color: [0, 1, .76, 1]
    background_image: ''
    ActionView:    
        ActionPrevious:
            title: 'Title'
            with_previous: False
            app_icon: ''    # Set the Icon to an empty String           
        ActionOverflow:
        ActionButton:
            text: 'Settings'
            on_press: app.open_settings()
        ActionButton:
            text: 'Quit'
            on_press: app.get_running_app().stop()
'''))

根据 Kivy 文档,app_icon 只不过是一个 StringProperty