Skip to content

Instantly share code, notes, and snippets.

@msmobileapps
Created January 21, 2021 10:38
Show Gist options
  • Select an option

  • Save msmobileapps/69ffc23de8264cc39964313d8c4adcde to your computer and use it in GitHub Desktop.

Select an option

Save msmobileapps/69ffc23de8264cc39964313d8c4adcde to your computer and use it in GitHub Desktop.
Dark mode programaticcally
//All App
findViewById<Button>(R.id.dark).setOnClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
if (Build.VERSION.SDK_INT >= 11) {
recreate();
}
}
//Local
findViewById<Button>(R.id.dark).setOnClickListener {
delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_YES;
if (Build.VERSION.SDK_INT >= 11) {
recreate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment