preferenceFragement没有设置共享preferences后才preferenceFragment是装 [英] PreferenceFragement does not set SharedPreferences until after PreferenceFragment is loaded

查看:202
本文介绍了preferenceFragement没有设置共享preferences后才preferenceFragment是装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在preferenceFragment preferences没有被添加到我的共享preference地图后,直到我加载preference片段。


  1. 这是preferenceFragment的预期行为?


  2. 如果有,是什么甚至之前应用在所有的 preferences.xml 指定的默认​​共​​享preferences的最佳方式用户访问preference片段?



解决方案

您可以把 preferenceManager.setDefaultValues​​(这一点,R.xml preferences,假的。); 在应用程序的启动活动的的onCreate()功能为用户启动首次应用程序尽快应用所有的默认值。

The PreferenceFragment preferences are not being added to my SharedPreference Map until after I load the preference fragment.

  1. Is this the intended behavior of the PreferenceFragment?

  2. If so, what is the best way to apply all of the defaults specified in preferences.xml to the SharedPreferences even before the user visits the preference fragment?

解决方案

You can put PreferenceManager.setDefaultValues(this, R.xml.preferences, false); in the onCreate() function of the app's launcher activity to apply all of the defaults as soon as a user launches the app for the first time.

这篇关于preferenceFragement没有设置共享preferences后才preferenceFragment是装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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