Android: Using Switch Preference pre API level 14

AndyAndroid picture AndyAndroid · Feb 29, 2012 · Viewed 15.4k times · Source

Pre-API Level 14 there is no switch preference. If I use preferences.xml to create my preference screen is there some way to distinguish between the API levels? So having a check box for old releases and a switch for API 14?

What would be the best way?

Answer

CommonsWare picture CommonsWare · Feb 29, 2012

If I use preferences.xml to create my preference screen is there some way to distinguish between the API levels? So having a check box for old releases and a switch for API 14?

Create a res/xml-v14/ directory that contains a preferences.xml that has your SwitchPreference. Create a res/xml/ directory that contains a preferences.xml file that replaces the SwitchPreference with a CheckBoxPreference. Android will load the right preferences.xml file edition based on the device version the app is running on.