mirror of
https://github.com/SoPat712/TrackCovid19.git
synced 2025-08-21 18:28:46 -04:00
SwitchPreference
Working, but not updating
This commit is contained in:
Binary file not shown.
@@ -4,7 +4,10 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
public class SettingsActivity extends AppCompatActivity {
|
public class SettingsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@@ -26,6 +29,19 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||||
|
SwitchPreference darkModeSwitch = findPreference("darkMode");
|
||||||
|
assert darkModeSwitch != null;
|
||||||
|
darkModeSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||||
|
} else {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,12 +27,12 @@
|
|||||||
<group
|
<group
|
||||||
android:id="@+id/menu_bottom"
|
android:id="@+id/menu_bottom"
|
||||||
android:checkableBehavior="none">
|
android:checkableBehavior="none">
|
||||||
<!--
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_yoursettings"
|
android:id="@+id/nav_yoursettings"
|
||||||
android:icon="@drawable/ic_action_name"
|
android:icon="@drawable/ic_action_name"
|
||||||
android:title="@string/item" />
|
android:title="@string/item" />
|
||||||
-->
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_sendFeedback"
|
android:id="@+id/nav_sendFeedback"
|
||||||
android:icon="@drawable/ic_action_name2"
|
android:icon="@drawable/ic_action_name2"
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
<string name="title_activity_settings">Settings</string>
|
<string name="title_activity_settings">Settings</string>
|
||||||
|
|
||||||
<!-- Preference Titles -->
|
<!-- Preference Titles -->
|
||||||
<string name="messages_header">Messages</string>
|
<string name="messages_header">Preferences</string>
|
||||||
<string name="sync_header">Sync</string>
|
<string name="sync_header">Sync</string>
|
||||||
|
|
||||||
<!-- Messages Preferences -->
|
<!-- Messages Preferences -->
|
||||||
|
@@ -1,19 +1,14 @@
|
|||||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/messages_header">
|
<PreferenceCategory app:title="@string/messages_header">
|
||||||
|
|
||||||
<EditTextPreference
|
|
||||||
app:key="signature"
|
|
||||||
app:title="@string/signature_title"
|
|
||||||
app:useSimpleSummaryProvider="true" />
|
|
||||||
|
|
||||||
<ListPreference
|
<SwitchPreference
|
||||||
app:defaultValue="reply"
|
android:key="darkMode"
|
||||||
app:entries="@array/reply_entries"
|
android:title="Dark Mode" />
|
||||||
app:entryValues="@array/reply_values"
|
|
||||||
app:key="reply"
|
|
||||||
app:title="@string/reply_title"
|
|
||||||
app:useSimpleSummaryProvider="true" />
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<!--
|
<!--
|
||||||
|
Reference in New Issue
Block a user