Skip to content

Instantly share code, notes, and snippets.

@hamzabasrai
Last active August 20, 2021 13:17
Show Gist options
  • Save hamzabasrai/692d4c7c7862d4ba771009cca81a644b to your computer and use it in GitHub Desktop.
Save hamzabasrai/692d4c7c7862d4ba771009cca81a644b to your computer and use it in GitHub Desktop.
@Override
public void onConfigurationChanged(Configuration configuration) {
super.onConfigurationChanged(configuration);
this.updateDarkMode(configuration);
}
private void updateDarkMode(Configuration configuration) {
// read the new night mode value
int currentNightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_NO:
forceDarkMode(WebSettingsCompat.FORCE_DARK_AUTO);
setDarkNavigationBar();
System.out.println("LIGHT THEME");
break;
case Configuration.UI_MODE_NIGHT_YES:
forceDarkMode(WebSettingsCompat.FORCE_DARK_ON);
setLightNavigationBar();
System.out.println("DARK THEME");
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment