簡體   English   中英

如何在 KivyMD 中更改 FloatingActionButton 的大小?

[英]How to change size of FloatingActionButton in KivyMD?

沒有參數更改有任何影響。 文檔中指定的set_size function 也不起作用。 user_font_size僅調整按鈕內的圖標大小,而不是按鈕本身。

from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
from kivymd.uix.button import MDFloatingActionButton


class MyApp(MDApp):
    def build(self):
        screen = MDScreen()
        btn_1 = MDFloatingActionButton(icon='account',
                                       pos_hint={'x': .2, 'y': .1},
                                       )
        btn_2 = MDFloatingActionButton(icon='account',
                                       pos_hint={'x': .3, 'y': .1},
                                       size=[16., 16.],
                                       user_font_size=64
                                       )
        btn_2.set_size((100, 100))
        screen.add_widget(btn_1)
        screen.add_widget(btn_2)
        return screen


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

精英:

size_hint不起作用並引發錯誤:

[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute

對於 KivyMD 0.104.1 版:

不幸的是,KivyMD 文檔似乎並不准確。 您可以使用大小提示(例如: size_hint=(0.1, 0.1) )設置 FloatingActionButton 的大小,以對應 window 大小。 如果要使用特定的像素值,請參見下文:

from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
from kivymd.uix.button import MDFloatingActionButton


class MyApp(MDApp):
    def build(self):
        screen = MDScreen()
        btn_1 = MDFloatingActionButton(icon='account',
                                       pos_hint={'x': .2, 'y': .1},
                                       )
        btn_2 = MDFloatingActionButton(icon='account',
                                       pos_hint={'x': .3, 'y': .1},
                                       size=[16., 16.], # Not necessary, doesn't have an effect
                                       user_font_size=64
                                       )
        btn_2.size = (100, 100) # Modified line
        screen.add_widget(btn_1)
        screen.add_widget(btn_2)
        return screen


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

無論出於何種原因,在初始化 MDFloatingActionButton 實例時都無法設置按鈕大小,只能在之后進行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM