0

I want to change the background of the ActionButtons which are inside the ActionOverflow in an ActionBar, however using the usual approach for Buttons (background_down, background_normal) seems not to work.

[ActionButton with black background] (https://raw.githubusercontent.com/Thomas-Adams/kivy_mananger/master/color_mananger/kivy-actionbutton.png)

Strangely enough when i click on that specific ActionButton (for instance 'List') the background changes as desired. However the 'normal' not pressed state has still a black background. I also tried tampering with background-image property, but to no avail. What do I miss? Does anybody has a clue or hint about this?

#:import get_color_from_hex kivy.utils.get_color_from_hex
<MainView>:
    ...
                ActionButton:
                    canvas.before:
                        Color:
                            rgba: get_color_from_hex('#d500f9')
                        Rectangle:
                            size: self.size
                            pos: self.pos
                    background_normal: 'electric-violet.png'
                    background_down: 'electric-violet-lighten.png'
                    background_disabled: ''
                    background_disabled_down: ''
                    background_color: get_color_from_hex('#d500f9')
                    text: 'Create'


Here's the link to the complete kv file

Thomas Adams
  • 13
  • 1
  • 5

2 Answers2

0

I figured it out by myself, in case anybody else is stuck here, instead of using the ActionButton widget i wrote my own widget which is based on ActionItem and Button :


class ColorActionButton(ActionItem, Button, EventDispatcher):
    color_name = StringProperty()
    base_dir = IMAGE_BASE_DIR
    b_normal = StringProperty()
    b_down = StringProperty()
    b_disabled_down = StringProperty()
    b_disabled = StringProperty()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def on_color_name(self, instance, value):
        self.b_normal = self.base_dir + value + SUFFIX
        self.b_down = self.base_dir + value + LIGHTEN_SUFFIX
        self.b_disabled_down = self.base_dir + value + DARKEN_SUFFIX

Using this now works like a charm.

Thomas Adams
  • 13
  • 1
  • 5
0

Another possibility is to create your own class based on ActionButton:

class MyActionButton(ActionButton):
    real_background_normal = StringProperty('')

And modify its style in your kv file:

<MyActionButton>:
    -background_normal: self.real_background_normal

Then elsewhere in your kv file, when you use MyActionButton, just use real_background_normal instead of background_normal:

MyActionButton:
    real_background_normal: 'electric-violet.png'
John Anderson
  • 35,991
  • 4
  • 13
  • 36