Migrate to DayNight Theme
This commit is contained in:
parent
a6ad96ccd7
commit
c509ecac47
12 changed files with 47 additions and 23 deletions
|
|
@ -31,6 +31,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.annotation.StyleRes;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
|
@ -120,6 +121,7 @@ public final class ThemeHelper {
|
|||
|
||||
final String selectedThemeKey = getSelectedThemeKey(context);
|
||||
|
||||
|
||||
int baseTheme = R.style.DarkTheme; // default to dark theme
|
||||
if (selectedThemeKey.equals(lightThemeKey)) {
|
||||
baseTheme = R.style.LightTheme;
|
||||
|
|
@ -288,4 +290,21 @@ public final class ThemeHelper {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDayNightMode(final Context context) {
|
||||
setDayNightMode(context, ThemeHelper.getSelectedThemeKey(context));
|
||||
}
|
||||
|
||||
public static void setDayNightMode(final Context context, final String selectedThemeKey) {
|
||||
final Resources res = context.getResources();
|
||||
|
||||
if (selectedThemeKey.equals(res.getString(R.string.light_theme_key))) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||
} else if (selectedThemeKey.equals(res.getString(R.string.dark_theme_key))
|
||||
|| selectedThemeKey.equals(res.getString(R.string.black_theme_key))) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue