Created
January 3, 2022 08:26
-
-
Save davidelp68/817083bf723496fdf64fed537fcdcb2e to your computer and use it in GitHub Desktop.
Android Studio - Night/Day
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
val appSettingPrefs: SharedPreferences = getSharedPreferences("AppSettingPrefs", Context.MODE_PRIVATE) | |
val sharedPrefsEdit: SharedPreferences.Editor = appSettingPrefs.edit() | |
val isNightMode = appSettingPrefs.getInt("NightMode", -1) | |
/*MODE_NIGHT_FOLLOW_SYSTEM = -1 | |
* MODE_NIGHT_AUTO = 0 (deprecated) | |
* MODE_NIGHT_NO = 1 | |
* MODE_NIGHT_YES = 2 | |
* MODE_NIGHT_AUTO_BATTERY = 3*/ | |
when (isNightMode) { | |
-1 -> { | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) | |
rbDefault!!.isChecked = true | |
txtMode!!.text = "Modalità: Predefinito da sistema attiva" | |
} | |
1 -> { | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | |
rbDay!!.isChecked = true | |
txtMode!!.text = "Modalità: Day attiva" | |
} | |
2 -> { | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) | |
rbNight!!.isChecked = true | |
txtMode!!.text = "Modalità: Night attiva" | |
} | |
else -> { | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | |
rbDay!!.isChecked = true | |
txtMode!!.text = "Modalità: Day attiva" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment