Compatibility for SwitchPreference (pre ICS)?

android, android-preferences, preferenceactivity

Solution

Is the SwitchPreference introduced in ICS compatible in the android-support-v4 library?

No, sorry.

However, it shouldn't be too tricky to backport it, if someone hasn't already.

Actually, it may be a bit of a pain, since it also requires a backport of Switch, and backporting widgets is sometimes troublesome because they frequently use package-private methods that backports cannot access.

I know I can make a separate resource file to distinguish the API version, but I'd like to avoid that if at all possible.

Well, that would certainly be way simpler than the alternatives:

the aforementioned backport

creating some sort of alias `Preference` mechanism that allows you to use `SwitchPreference` on newer devices and `CheckBoxPreference` on older devices with only one resource file

Problem

Is the `SwitchPreference` introduced in ICS compatible in the android-support-v4 library? I'm trying to update some old projects and would like to use SwitchPreferences if possible. I know I can make a separate resource file to distinguish the API version, but I'd like to avoid that if at all possible.

Original source