Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch vs. SwitchCompat

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?

like image 705
Simon Warta Avatar asked Dec 20 '16 09:12

Simon Warta


People also ask

What is SwitchCompat?

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.

How do I turn on my Android switch?

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.


1 Answers

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.

SwitchCompat and Switch image on Android 4 and Android 7

like image 64
R. Zagórski Avatar answered Oct 18 '22 20:10

R. Zagórski