Skip to content

Commit 16aa947

Browse files
committed
Add darkmode
1 parent 2a1d653 commit 16aa947

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

app/src/main/java/com/example/mynotes/ui/fragments/NotesFragment.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ class NotesFragment : Fragment() {
7171
override fun onOptionsItemSelected(item: MenuItem): Boolean {
7272

7373
return when (item.itemId) {
74-
// R.id.mode -> {
75-
// val mode =
76-
// if ((resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
77-
// AppCompatDelegate.MODE_NIGHT_YES
78-
// } else {
79-
// AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
80-
// }
81-
//
82-
// // Change UI Mode
83-
// AppCompatDelegate.setDefaultNightMode(mode)
84-
// true
85-
// }
74+
R.id.mode -> {
75+
val mode =
76+
if ((resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
77+
AppCompatDelegate.MODE_NIGHT_YES
78+
} else {
79+
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
80+
}
81+
82+
// Change UI Mode
83+
AppCompatDelegate.setDefaultNightMode(mode)
84+
true
85+
}
8686

8787
R.id.delete -> {
8888
deleteAllNotes()

app/src/main/res/layout/fragment_notes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools">
55

66
<androidx.constraintlayout.widget.ConstraintLayout
7+
android:configChanges="uiMode"
78
android:layout_width="match_parent"
89
android:layout_height="match_parent"
910
tools:context=".ui.fragments.NotesFragment">

0 commit comments

Comments
 (0)