Last active
January 27, 2020 14:16
-
-
Save shanmugasanthosh7/1c5c60a8e73483035ebd547ea619fe42 to your computer and use it in GitHub Desktop.
Theme Utils for light and dark.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThemeUtils { | |
/** | |
* MODE_NIGHT_NO | |
*/ | |
public static final int LIGHT = AppCompatDelegate.MODE_NIGHT_NO; | |
/** | |
* MODE_NIGHT_YES | |
*/ | |
public static final int DARK = AppCompatDelegate.MODE_NIGHT_YES; | |
public static final String APPLIED_THEME = "APPLIED_THEME"; | |
public static void applyTheme(int mode) { | |
AppCompatDelegate.setDefaultNightMode(mode); | |
} | |
public static int getCurrentMode(Context context) { | |
int mode = -1; | |
int currentNightMode = context.getResources().getConfiguration().uiMode | |
& Configuration.UI_MODE_NIGHT_MASK; | |
switch (currentNightMode) { | |
case Configuration.UI_MODE_NIGHT_NO: | |
// Night mode is not active, we're in day time | |
mode = LIGHT; | |
break; | |
case Configuration.UI_MODE_NIGHT_YES: | |
// Night mode is active, we're at night! | |
mode = DARK; | |
break; | |
} | |
return mode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment