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
Try this code:
public class SettingsActivity extends PreferenceActivity {
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_settings);
PreferenceScreen rootScreen = getPreferenceManager()
.createPreferenceScreen(this);
setPreferenceScreen(rootScreen);
Preference NotifCheck=null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
NotifCheck = new SwitchPreference(this);
} else {
NotifCheck = new CheckBoxPreference(this);
}
NotifCheck.setKey("ShowNotification");
NotifCheck.setTitle(R.string.ShowNotification);
NotifCheck.setEnabled(true);
rootScreen.addPreference(NotifCheck);
// Show the Up button in the action bar.
setupActionBar();
}
}