Android switchpreference how can i set the switch preference default value?
The code is correct just use switchPreferenceCompact instead of SwitchPreference
<SwitchPreferenceCompat
app:key="promoNofitficationOnOff"
app:summaryOff="@string/notification_summary_off"
app:summaryOn="@string/notification_summary_on"
app:defaultValue="true"
app:title="@string/promo_notification_title" />
In your MainActivity onCreate
method add this line
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
You can read about it at http://developer.android.com/reference/android/preference/PreferenceManager.html#setDefaultValues(android.content.Context, int, boolean)