问题描述
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?
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.
这篇关于Switch 与 SwitchCompat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!