android 中 switch 和 switchcompat 之间的区别?

difference between switch and switchcompat in android?

有人可以解释一下 SwitchSwitchCompat 之间的真正区别吗?我可以将两者都用作切换按钮吗?都可以支持低版本的android。提前致谢

正如评论中已经提到的 beardedbeast,这些小部件彼此之间的区别仅在于支持的 API 级别。 您可以将它们用于同一目的,但不能同时使用以避免不必要的复杂化。

关于使用 Compat 小部件时的已知问题,developers.blogspot 有一个答案:

You don’t need to do anything special to make these work, just use these controls in your layouts as usual and AppCompat will do the rest (with some caveats; see the FAQ below).

还有一点,这里没有提到。要使 SwitchCompat(和其他 Compat 小部件)具有正确的外观和行为,请检查父级 Activity(或您用来扩展 Compat 视图的 LayoutInflater)的样式是否为 Theme.AppCompat.