本文介绍了Switch 与 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?

解决方案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:59