PreferenceActivity如何使用自定义首选项文件 [英] How can a PreferenceActivity use a custom preference file

查看:74
本文介绍了PreferenceActivity如何使用自定义首选项文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对偏好的第一次尝试是不了解PreferenceActivity的.因此,现在我有了一个将所有用户首选项存储在特定首选项文件中的应用.

My first attempt at preferences was without knowledge of PreferenceActivity. So now I have an app that stores all user preferences in a specific preference file.

我想迁移到使用PreferenceActivity,但我也希望我的用户保留其首选项.

I want to migrate to using a PreferenceActivity but I also want my users to keep their preferences.

是否可以告诉我的PreferenceActivity对所有首选项使用该特定文件?

Is there a way to tell my PreferenceActivity to use that specific file for all preferences?

推荐答案

您可以在应用程序的开头阅读所有首选项,然后使用

You could read all the preferences at the beginning of your app, and then store them in the Preferences using

Editor e = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit();
e.putBoolean("yourPreference", true);
e.putString("yourOtherPreference", "This is the Value");
...
e.commit();

我希望对您有帮助

这篇关于PreferenceActivity如何使用自定义首选项文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆