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
package com.dm.tutorialdaynight3 | |
import android.content.Context | |
import android.content.SharedPreferences //Importazione della Classe SharedPreferences | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.RadioButton | |
import android.widget.TextView | |
import androidx.appcompat.app.AppCompatDelegate //Importazione della Classe AppCompactDelegate |
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) { |
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 mode = AppCompatDelegate.getDefaultNightMode() | |
sharedPrefsEdit.putInt("NightMode", mode) | |
sharedPrefsEdit.apply() |
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
package com.dm.tutorialdaynight2 | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.RadioButton | |
import androidx.appcompat.app.AppCompatDelegate //Importazione della Classe AppCompactDelegate | |
class MainActivity : AppCompatActivity() { | |
private var rbDay: RadioButton? = null |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context=".MainActivity"> | |
<TextView |
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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="android:windowBackground">@color/backgroundwindow</item> | |
</style> |
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
<item name="android:windowBackground">@color/backgroundwindow</item> |
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
//Imposta il tema in base all'attivazione della modalità risparmio energia | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY) |
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
//Imposta il tema in base all'impostazione di sistema | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) |
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
//Imposta il tema chiaro | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) |
NewerOlder