A Switch is a two-state toggle switch widget that can select between two options and a SwitchCompat is a version of the Switch widget which on devices back to API v7. It does not make any attempt to use the platform provided widget on those devices which it is available normally.
Given that both are available to any modern Android 4+ app developer, what are the reasons to use one or another? What are the core differences?
SwitchCompat is a complete backport of the core Switch widget that brings the visuals and functionality of the toggle widget to older versions of the Android platform. Unlike other widgets in this package, SwitchCompat is not automatically used in layouts that include the <Switch> element.
In android, Switch is a two-state user interface element that is used to display ON (Checked) or OFF (Unchecked) states as a button with thumb slider. By using thumb, the user may drag back and forth to choose an option either ON or OFF.
There is a huge difference. Switch
is platform dependent. It can look differently on different version systems. On post-lollipop devices it inherits from Material Design styles, on pre-lollipop it inherits from holo styles.
SwitchCompat
inherits from Material Design on every system version.
Of course context Activity
must be AppCompat
one.
Using components from support libraries you ensure the same behaviour on all system versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With