2011-02-09 127 views
6

在共享首选项中有一些默认值通常很好。有没有一种很好的方法来从xml文件或属性文件初始化它们?寻找最好的方式来做到这一点。谢谢。Android共享首选项初始化

+0

可能重复(HTTP ://stackoverflow.com/questions/2691772/android-preferences-how-to-load-the-default-values-when-the-user-hasnt-used-th) – 2014-08-13 09:13:57

回答

0
@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // Make sure default values are applied. In a real app, you would 
     // want this in a shared function that is used to retrieve the 
     // SharedPreferences wherever they are needed. 
     PreferenceManager.setDefaultValues(getActivity(), 
       R.xml.advanced_preferences, false); 

} 
[Android的偏好?:如何当用户不使用偏好屏幕加载默认值]的