androidandroid-appcompatlintmaterial-components-androidandroid-switch

Warning : Use SwitchCompat from AppCompat or SwitchMaterial from Material library


What is the difference between these 2 objects (SwitchCompat and SwitchMaterial)? I have tried them and visually they are identical.

By the way, why did they remove the Switch class? Do you know which UI element is supposed to replace it in the future?


Solution

  • The SwitchMaterial:

    The SwitchCompat:

    By the way, why did they remove the Switch class?

    The Switch class is not removed. It is provided by the android framework like other widgets as Button,TextView.. and the appcompat and material components libraries provide an updated version of them (like AppCompatButton, MaterialButton...).

    There is a different with these widgets. Using an AppCompat theme there is the AppCompatViewInflater that automatically replaces all usages of core Android widgets inflated from layout files by the AppCompat extensions of those widgets (for example a Button is replaced by AppCompatButton).
    Using the Theme.MaterialComponents there is the MaterialComponentsViewInflater that replaces some framework widgets with Material Components ones at inflation time, provided a Material Components theme is in use (for example a Button is replaced by MaterialButton).

    It is NOT true for the SwitchMaterial and the SwitchCompat.The reason for that is due to the AppCompat SwitchCompat not actually extending from the framework Switch class.