Added support for theme recreation after application relaunch (untested)
This commit is contained in:
parent
5920139710
commit
0e554686e3
|
@ -9,7 +9,8 @@
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true">
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".SplashScreenActivity"
|
android:name=".SplashScreenActivity"
|
||||||
|
@ -24,15 +25,13 @@
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.MainActivity"
|
android:name=".ui.MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name">
|
||||||
android:theme="@style/LightTheme">
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.AboutActivity"
|
android:name=".ui.AboutActivity"
|
||||||
android:parentActivityName=".ui.MainActivity"
|
android:parentActivityName=".ui.MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name">
|
||||||
android:theme="@style/LightTheme">
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
|
|
|
@ -19,15 +19,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
when (currentVal.toInt()){
|
when (currentVal.toInt()){
|
||||||
0 -> {
|
0 -> {
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
activity?.recreate()
|
|
||||||
}
|
}
|
||||||
1 -> {
|
1 -> {
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
activity?.recreate()
|
|
||||||
}
|
}
|
||||||
else ->{
|
else ->{
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
activity?.recreate()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
|
|
@ -22,16 +22,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
when (AppCompatDelegate.getDefaultNightMode()) {
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.getDefaultNightMode())
|
||||||
AppCompatDelegate.MODE_NIGHT_YES -> {
|
|
||||||
setTheme(R.style.DarkTheme)
|
|
||||||
}
|
|
||||||
AppCompatDelegate.MODE_NIGHT_NO -> {
|
|
||||||
setTheme(R.style.LightTheme)
|
|
||||||
}
|
|
||||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.onCreate(null)
|
super.onCreate(null)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="DarkTheme" parent="Theme.MaterialComponents.NoActionBar">
|
<style name="MainTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||||
|
|
||||||
<item name="colorPrimary">#1490D7</item>
|
<item name="colorPrimary">#1490D7</item>
|
||||||
<item name="colorPrimaryVariant">#804EAFF5</item>
|
<item name="colorPrimaryVariant">#804EAFF5</item>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="LightTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
|
<style name="MainTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||||
|
|
||||||
<item name="colorPrimary">#1490D7</item>
|
<item name="colorPrimary">#1490D7</item>
|
||||||
<item name="colorPrimaryVariant">#2C7EB9</item>
|
<item name="colorPrimaryVariant">#2C7EB9</item>
|
||||||
|
|
Loading…
Reference in New Issue