Skip to content

Instantly share code, notes, and snippets.

@vamjakuldip
Created October 30, 2021 08:18
Show Gist options
  • Save vamjakuldip/6e9672b2bd5788f3f960bb72c4aefa55 to your computer and use it in GitHub Desktop.
Save vamjakuldip/6e9672b2bd5788f3f960bb72c4aefa55 to your computer and use it in GitHub Desktop.
Used this theme helper to change app then between light and drak manually.
object ThemeHelper {
const val LIGHT_MODE = "light"
const val DARK_MODE = "dark"
const val DEFAULT_MODE = "default"
fun applyTheme(theme: String) {
when (theme) {
LIGHT_MODE -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
DARK_MODE -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
else -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment