Created
October 30, 2021 08:18
-
-
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.
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
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