KivyMD - MDFloatingActionButton never has its shadow before pressing

30 Views Asked by At

I'm trying to put a MDFloatingActionButton in my app.

The button gets its shadow only after pressing it. How can I fix it?

environment:

Python==3.11.5

Kivy==2.3.0

KivyMD==1.2.0

example.py:

from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.uix.button import MDFloatingActionButton

KV = '''
MDScreen:
    MDFloatingActionButton:
        icon: 'delete-outline'
        type: 'large'
        md_bg_color: 'green'
        icon_color: 'white'
        elevation: 5
        pos_hint: {'center_x': .5, 'center_y': .5}
'''

class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)

Example().run()

Thank you!

1

There are 1 best solutions below

0
John Anderson On

Looks like a bug in the MDFloatingActionButton. Try modifying your kv to trigger the drawing of the shadow by using Clock.schedule_once()

#:import Clock kivy.clock.Clock
MDScreen:
    MDFloatingActionButton:
        icon: 'delete-outline'
        type: 'large'
        md_bg_color: 'green'
        icon_color: 'white'
        elevation: 5
        pos_hint: {'center_x': .5, 'center_y': .5}
        on_parent: Clock.schedule_once(lambda dt: self._anim_raised.start(self))