【发布时间】:2011-09-04 11:54:58
【问题描述】:
当应用程序第一次启动时,我想使用 'android:defaultValue' 属性存储我在我的 prefences.xml 中定义的所有默认值,但其中一些没有存储在设备上 - 可以有人告诉我为什么吗?
<?xml version="1.0" encoding="utf-8"?>
<PreferenceCategory android:title="@string/prefs_cat_title_x">
<ListPreference
android:key="@string/prefs_key_1"
android:title="@string/prefs_title_1"
android:summary="@string/prefs_summary_1"
android:entries="@array/array1"
android:entryValues="@array/array1"
android:defaultValue="@string/prefs_default_1"/>
<com.myapp.TimePreference
android:key="@string/prefs_key_2"
android:title="@string/prefs_title_2"
android:defaultValue="@string/prefs_default_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.myapp.TimePreference
android:key="@string/prefs_key_3"
android:title="@string/prefs_title_3"
android:defaultValue="@string/prefs_default_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListPreference
android:key="@string/prefs_key_4"
android:title="@string/prefs_title_4"
android:summary="@string/prefs_summary_4"
android:entries="@array/array2"
android:entryValues="@array/array2"
android:defaultValue="@string/prefs_default_4"/>
<CheckBoxPreference
android:key="@string/prefs_key_5"
android:title="@string/prefs_title_5"
android:summary="@string/prefs_summary_5"
android:defaultValue="false"/>
<CheckBoxPreference
android:key="@string/prefs_key_6"
android:title="@string/prefs_title_6"
android:summary="@string/prefs_summary_6"
android:defaultValue="false"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefs_cat_title_common">
<com.myapp.DatabaseResetPreference
android:title="@string/prefs_title_7"
android:summary="@string/prefs_summary_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</PreferenceCategory>
【问题讨论】:
标签: android store default-value sharedpreferences android-preferences