SwitchPreference

Working, but not updating
This commit is contained in:
2020-11-16 10:32:50 -05:00
parent 92418ed73e
commit 290b17d029
5 changed files with 26 additions and 15 deletions

View File

@@ -4,7 +4,10 @@ import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
public class SettingsActivity extends AppCompatActivity {
@@ -26,6 +29,19 @@ public class SettingsActivity extends AppCompatActivity {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String 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;
}
});
}
}
}

View File

@@ -27,12 +27,12 @@
<group
android:id="@+id/menu_bottom"
android:checkableBehavior="none">
<!--
<item
android:id="@+id/nav_yoursettings"
android:icon="@drawable/ic_action_name"
android:title="@string/item" />
-->
<item
android:id="@+id/nav_sendFeedback"
android:icon="@drawable/ic_action_name2"

View File

@@ -38,7 +38,7 @@
<string name="title_activity_settings">Settings</string>
<!-- Preference Titles -->
<string name="messages_header">Messages</string>
<string name="messages_header">Preferences</string>
<string name="sync_header">Sync</string>
<!-- Messages Preferences -->

View File

@@ -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">
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="reply"
app:entries="@array/reply_entries"
app:entryValues="@array/reply_values"
app:key="reply"
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
android:key="darkMode"
android:title="Dark Mode" />
</PreferenceCategory>
<!--