我已经在我的应用程序中设置了首选项屏幕作为设置选项,但是我对如何在用户选择或更改选项时完成更改完全感到困惑。如何使事情上的首做被改变?
这里是我的PreferenceScreen的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Notifications">
<RingtonePreference
android:summary="Choose a Ringtone"
android:title="Notification Ringtone"
android:key="ringtonePref" />
<ListPreference
android:title="Notification Timer"
android:summary="Select when to Notify"
android:dialogTitle="Show Notification after every:"
android:positiveButtonText="OK"
android:negativeButtonText="Cancel"
android:entries="@array/entries"
android:entryValues="@array/entries"
android:key="listPrefs" />
<ListPreference
android:title="LED Color"
android:summary="Choose LED Color"
android:positiveButtonText="OK"
android:negativeButtonText="Cancel"
android:entries="@array/colors"
android:entryValues="@array/colors"
android:key="listPrefs2" />
<CheckBoxPreference
android:title="LED"
android:defaultValue="true"
android:summary="Flash LED or Not"
android:key="checkBoxPrefs2"/>
<CheckBoxPreference
android:title="Vibrate"
android:defaultValue="true"
android:summary="Vibrate on receiving Notification"
android:key="checkBoxPrefs3" />
</PreferenceCategory>
<PreferenceCategory android:title="Invite">
<Preference android:summary="Send invitation to more peoples so that\nthey can also Learn more and more Duas."/>
</PreferenceCategory>
<PreferenceCategory android:title="Version">
<Preference
android:key="versionPrefs"
android:summary="Version 1.0\nThank you for Downloading the App." />
</PreferenceCategory>
</PreferenceScreen>
这里是我Settings.class:
public class Settings extends PreferenceActivity implements OnPreferenceChangeListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
//setting the properties of Action Bar
ActionBar actionBar = getActionBar();
actionBar.setTitle(Html.fromHtml("<font color='#FFFFFF'><strong>Settings</strong></font>"));
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
actionBar.setDisplayHomeAsUpEnabled(true);
PreferenceManager.setDefaultValues(this, R.xml.settings, true);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// TODO Auto-generated method stub
return false;
}
}
我不知道我要补充什么码onPreferenceChange让我的偏好实际上做的改变。
请告诉我。
任何帮助将是非常赞赏。
感谢您的宝贵的时间。
http://developer.android.com/reference/android/preference/package-summary.html –
@Hammad纳西尔如果妳想要保存UR设置使用SharedPreferences请查看以下链接的http:// developer.android.com/reference/android/content/SharedPreferences.html –
@shylendra我想要的东西就像是假设有一个振动选项,如果用户检查它会比振动发生,如果用户将取消它的振动不会发生。请帮我解决一下这个。 –