问题
Can someone please explain the real difference between Switch
and SwitchCompat
.Can I use both as toggle button. can both support lower versions of android. thanks in advance
回答1:
As beardedbeast already mentioned in comment, these widgets differ from each other only by the supported API level. You can use both of them for the same purpose but not simultaneously to avoid unnecessary complication.
As for known issues when using Compat widgets, there is an answer from 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).
And one points, which is not mentioned there. To have correct look and behavior of SwitchCompat
(and other Compat widgets) check if the parent Activity
(or LayoutInflater
which you are using to inflate Compat view) is styled with Theme.AppCompat
.
来源:https://stackoverflow.com/questions/33604164/difference-between-switch-and-switchcompat-in-android