从对话框保存首选项

时间:2012-08-15 14:41:20

标签: android sharedpreferences android-preferences android-dialog

在我的Dialog屏幕中打开自定义Preferences后,如何在Dialog消失后保存到该特定偏好设置?

public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.task_preferences);

        Preference dialogPreference = (Preference) findPreference(getString(R.string.clock_font_color));
        dialogPreference.setOnPreferenceClickListener( new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                dialog(); ////How save here//????
                return true;
            }
        });
    }
}

1 个答案:

答案 0 :(得分:1)

SharedPreferences preferences = getPreferenceManager().getSharedPreferences(); 
preferences.edit().putString("clockfontcolor", "-9856").commit();