:github_url: https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/behaviors/toggle_behavior.py

ToggleButton
============

.. py:module:: kivymd.uix.behaviors.toggle_behavior

.. autoapi-nested-parse::

   Behaviors/ToggleButton
   ======================

   This behavior must always be inherited after the button's Widget class since it
   works with the inherited properties of the button class.

   example:

   .. code-block:: python

       class MyToggleButtonWidget(MDButton, MDToggleButton):
           # [...]
           pass


   .. tabs::

       .. tab:: Declarative KV style

           .. code-block:: python

               from kivy.lang import Builder

               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:
                           group: "x"

                           MDButtonText:
                               text: "Show ads"

                       MyToggleButton:
                           group: "x"

                           MDButtonText:
                               text: "Do not show ads"

                       MyToggleButton:
                           group: "x"

                           MDButtonIcon:
                               icon: "pencil"

                           MDButtonText:
                               text: "Does not matter"
               '''


               class MyToggleButton(MDButton, MDToggleButton):
                   ...


               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()

       .. tab:: Declarative python style

           .. code-block:: python

               from kivymd.app import MDApp
               from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
               from kivymd.uix.boxlayout import MDBoxLayout
               from kivymd.uix.button import MDButton, MDButtonText, MDButtonIcon
               from kivymd.uix.screen import MDScreen


               class MyToggleButton(MDButton, MDToggleButton):
                   ...


               class Test(MDApp):
                   def build(self):
                       self.theme_cls.theme_style = "Dark"
                       self.theme_cls.primary_palette = "Orange"
                       return (
                           MDScreen(
                               MDBoxLayout(
                                   MyToggleButton(
                                       MDButtonText(
                                           text="Show ads",
                                       ),
                                   group="x",
                                   ),
                                   MyToggleButton(
                                       MDButtonIcon(
                                           icon="pencil",
                                       ),
                                       MDButtonText(
                                           text="Do not show ads",
                                       ),
                                       group="x",
                                   ),
                                   MyToggleButton(
                                       MDButtonText(
                                           text="Does not matter",
                                       ),
                                       group="x",
                                   ),
                                   adaptive_size=True,
                                   spacing="12dp",
                                   pos_hint={"center_x": .5, "center_y": .5},
                               ),
                           )
                       )


               Test().run()

   .. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/toggle-button-1.gif
       :align: center

   You can inherit the ``MyToggleButton`` class only from the following classes
   ----------------------------------------------------------------------------

   - :class:`~kivymd.uix.button.MDRaisedButton`
   - :class:`~kivymd.uix.button.MDFlatButton`
   - :class:`~kivymd.uix.button.MDRectangleFlatButton`
   - :class:`~kivymd.uix.button.MDRectangleFlatIconButton`
   - :class:`~kivymd.uix.button.MDRoundFlatButton`
   - :class:`~kivymd.uix.button.MDRoundFlatIconButton`
   - :class:`~kivymd.uix.button.MDFillRoundFlatButton`
   - :class:`~kivymd.uix.button.MDFillRoundFlatIconButton`


API - :mod:`kivymd.uix.behaviors.toggle_behavior`
-------------------------------------------------

.. py:class:: MDToggleButtonBehavior(*args, **kwargs)




   This `mixin <https://en.wikipedia.org/wiki/Mixin>`_ class provides
   :mod:`~kivy.uix.togglebutton` behavior. Please see the
   :mod:`togglebutton behaviors module <kivy.uix.behaviors.togglebutton>`
   documentation for more information.

   .. versionadded:: 1.8.0

   .. py:attribute:: background_normal

      Color of the button in ``rgba`` format for the 'normal' state.

      :attr:`background_normal` is a :class:`~kivy.properties.ColorProperty`
      and is defaults to `None`.


   .. py:attribute:: background_down

      Color of the button in ``rgba`` format for the 'down' state.

      :attr:`background_down` is a :class:`~kivy.properties.ColorProperty`
      and is defaults to `None`.


   .. py:attribute:: font_color_normal

      Color of the font's button in ``rgba`` format for the 'normal' state.

      :attr:`font_color_normal` is a :class:`~kivy.properties.ColorProperty`
      and is defaults to `None`.


   .. py:attribute:: font_color_down

      Color of the font's button in ``rgba`` format for the 'down' state.

      :attr:`font_color_down` is a :class:`~kivy.properties.ColorProperty`
      and is defaults to `None`.


   .. py:method:: set_properties(*args)




