我正在尝试使用 AndroidPreferenceScreen
作为一种方便的方式来布局我的用户设置,但我不想将首选项保存到设备共享首选项中。这是可能的,还是我应该使用不同的机制,例如ListView
?
使用该PreferenceScreen
类型似乎真的很方便,因为我需要不同的小部件(即开关、编辑文本)。但是我已经遇到了持久性问题,即。即使在我不希望的会话中,我输入的任何内容也会持续存在。
设置.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Preference
android:key="settings_type"
android:title="@string/label_type" />
<EditTextPreference
android:key="settings_edit_name"
android:title="@string/label_name"
android:dialogTitle="Enter a name"
android:singleLine="true" />
<SwitchPreference
android:key="settings_edit_state"
android:title="@string/label_state"
android:summary="Enable or disable the state" />
</PreferenceScreen>