Fix theme and icon color on startup

This commit is contained in:
CappielloAntonio 2021-04-12 17:56:09 +02:00
parent ecc941dc11
commit b3ae8b1fff
7 changed files with 20 additions and 4 deletions

View file

@ -1,11 +1,14 @@
package com.cappielloantonio.play.helper;
import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
public class ThemeHelper {
private static final String TAG = "ThemeHelper";
public static final String LIGHT_MODE = "light";
public static final String DARK_MODE = "dark";
public static final String DEFAULT_MODE = "default";
@ -13,14 +16,19 @@ public class ThemeHelper {
public static void applyTheme(@NonNull String themePref) {
switch (themePref) {
case LIGHT_MODE: {
Log.d(TAG, "applyTheme: LIGHT");
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
}
case DARK_MODE: {
Log.d(TAG, "applyTheme: DARK");
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
}
default: {
Log.d(TAG, "applyTheme: SYSTEM");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else {