79616606

Date: 2025-05-11 14:55:38
Score: 2
Natty:
Report link

first go to kivymd\uix\behaviors and edit toggle_behavior.py. just copy and past the code in this link https://github.com/sudoevans/KivyMD/blob/05148dda1d9c697a611cb4452a07f3b9733c4f50/kivymd/uix/behaviors/toggle_behavior.py
this won't fix the bug but will help make a work around.
now the following should work:

from kivy.lang import Builder
# Version: 2.0.1.dev0
from kivymd.app import MDApp
from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.button import MDButton

KV = '''
MDScreen:

    MDBoxLayout:
        adaptive_size: True
        spacing: "12dp"
        pos_hint: {"center_x": .5, "center_y": .5}

        MyToggleButton:
            text: "Show ads"
            group: "x"

        MyToggleButton:
            text: "Do not show ads"
            group: "x"

        MyToggleButton:
            text: "Does not matter"
            group: "x"
'''


class MyToggleButton(MDButton, MDToggleButton):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.background_down = '#FF5722' # This is the trick. if you find away to get hex from self.theme_cls.primary_palette that would be better but I don't know so just give it any hex you want.


class Test(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"
        return Builder.load_string(KV)


Test().run()
Reasons:
  • Blacklisted phrase (1): this link
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user30506750