Add Dialog to change theme.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@@ -8,6 +9,7 @@ import androidx.core.widget.doOnTextChanged
|
||||
import kotlinx.android.synthetic.main.content_main.*
|
||||
import android.text.InputType
|
||||
import android.widget.ScrollView
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@@ -256,6 +258,10 @@ class MainActivity : AppCompatActivity() {
|
||||
undoLastRound()
|
||||
true
|
||||
}
|
||||
R.id.action_theme -> {
|
||||
chooseThemeDialog()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
@@ -317,4 +323,44 @@ class MainActivity : AppCompatActivity() {
|
||||
submit.isEnabled = false
|
||||
}
|
||||
|
||||
|
||||
private fun chooseThemeDialog() {
|
||||
|
||||
val builder = AlertDialog.Builder(this)
|
||||
builder.setTitle(getString(R.string.choose_theme_text))
|
||||
val styles = arrayOf("Light","Dark","System default")
|
||||
|
||||
var checkedItem = when(AppCompatDelegate.getDefaultNightMode()) {
|
||||
AppCompatDelegate.MODE_NIGHT_NO -> 0
|
||||
AppCompatDelegate.MODE_NIGHT_YES -> 1
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> 2
|
||||
else -> -1
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user