1

所以我对动态壁纸中的偏好有一个很大的愚蠢问题。

首先,PreferenceManager.getDefaultSharedPreferences, 不起作用。我在我的 Main 类中调用它,它是函数 onCreate 中的 WallpaperService 的子类。对于参数,我先尝试了“this”,然后尝试了this.getBaseContext(),但没关系。所以,当我打印这些值时,什么也没有出现!

其次,我在这里的另一个答案中看到,要放置一些默认值,请使用类似PreferenceManager.setDefaultValues(this.getBaseContext(), R.xml.setting, true);. 所以,这根本没有得到我的 defaultValues。它们都是零,甚至我的一个值setting.xml也不会出现在列表中。我明确地android:defaultValue为他们每个人设置了一个。

请注意,一旦我将它们中的每一个的值放在首选项中,这个问题就不会发生。但是,对于安装我的应用程序的人来说,它需要在第一次启动时运行。

4

1 回答 1

1

Preferences are a bear. I always start with a working example, and then modify it to suit my needs; it's impossible to remember the formalisms :-). The "obvious" place to start is the "second" Cube example in the SDK, which uses a preferences activity to choose between cube and dodecahedron shapes. For something more sophisticated, you might wanna look at Moonblink's "Substrate" package, which combines multiple wallpapers, and has complex settings. Project home is here: http://code.google.com/p/moonblink/wiki/Substrate , then click Source at top left, then Browse, Trunk, Substrate, src, etc. GF

于 2011-06-24T05:39:18.820 回答