Custom preference to apply themes
You can download the example APK from this repo here: https://github.com/enricocid/ThemePreference/raw/master/project/app/app-release.apk
<SwitchPreference android:defaultValue="false"
android:key="pref_lightOrDark"
android:title="@string/dark_theme"/>
<com.enrico.themepreference.ThemePreference
android:defaultValue="0"
android:key="pref_chooseAccent"
android:persistent="true"
android:summary="?attr/colorAccent"
android:title="@string/pref_theme_title"/>
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getBaseContext(), this.getTheme());
ThemeUtils.applyTheme(contextThemeWrapper, this);