<string-array name="themeKeys" translatable="false">
<item>themeLight</item>
<item>themeDefault</item>
+ <item>themeSystem</item>
</string-array>
<string-array name="themes">
<item>Light theme</item>
<item>Dark theme (default)</item>
+ <item>System theme</item>
</string-array>
</resources>
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
final String theme = prefs.getString(appContext.getString(R.string.themeKey), "themeLight");
if (theme.equals("themeLight")) {
return Theme.LIGHT;
+ } else if (theme.equals("themeSystem")) {
+ int mode = (appContext.getResources().getConfiguration().uiMode &
+ Configuration.UI_MODE_NIGHT_MASK);
+ return ((mode == Configuration.UI_MODE_NIGHT_YES) ?
+ Theme.DEFAULT :
+ Theme.LIGHT);
} else {
return Theme.DEFAULT;
}