You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

KivyMD 2.0.1版本中MDButton使用md_bg_color无法修改背景颜色的问题求助

KivyMD 2.0.1版本中MDButton使用md_bg_color无法修改背景颜色的问题求助

我现在在KivyMD 2.0.1版本里,想给kv文件中的MDButton设置自定义背景色,试了好几种写法都没效果,实在没辙了来请教各位!

我最初的尝试(已经简化到只保留按钮相关代码):

MDScreen:
    MDButton:
        style: "tonal"
        md_bg_color: [232/255, 114/255, 83/255, 1]

        MDButtonText:
            text: "Next"

之后我还试过这种写法,连canvas.before都用上了,还是不行:

MDButton:
    style: "filled"
    md_bg_color: [232/255, 114/255, 83/255, 1]
    pos_hint: {"center_x": 0.5, "center_y": 0.5}  # 调整位置
    size_hint: 0.3, 0.1  # 调整尺寸(可选)
    canvas.before:
        Color:
            rgba: [232/255, 114/255, 83/255, 1]  # 自定义按钮颜色
        RoundedRectangle:
            pos: self.pos
            size: self.size
            radius: [10]  # 圆角(可选)
    MDButtonText:
        text: "Next"

我已经看过官方文档,也搜了不少类似问题,但大部分都是针对旧版Kivy的,和KivyMD 2.0.1的差异挺大的,找不到适配的解决方法,有没有大佬能指点一下?

备注:内容来源于stack exchange,提问作者Dallo81

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:29:31