Skip to content

Instantly share code, notes, and snippets.

@manuelernesto
Created June 1, 2020 13:19
Show Gist options
  • Save manuelernesto/8db34060cb812c056baf6347be7373a7 to your computer and use it in GitHub Desktop.
Save manuelernesto/8db34060cb812c056baf6347be7373a7 to your computer and use it in GitHub Desktop.
private fun chooseThemeDialog() {
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.choose_theme_text))
val styles = arrayOf("Light","Dark","System default")
val checkedItem = 0
builder.setSingleChoiceItems(styles, checkedItem) { dialog, which ->
when (which) {
0 -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
delegate.applyDayNight()
dialog.dismiss()
}
1 -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
delegate.applyDayNight()
dialog.dismiss()
}
2 -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
delegate.applyDayNight()
dialog.dismiss()
}
}
}
val dialog = builder.create()
dialog.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment