/** * Inflates the given XML resource and adds the preference hierarchy to the current preference * hierarchy. * * @param preferencesResId The XML resource ID to inflate. */ public void addPreferencesFromResource(@XmlRes int preferencesResId) { requirePreferenceManager(); setPreferenceScreen( mPreferenceManager.inflateFromResource( getActivity(), preferencesResId, getPreferenceScreen())); }
/** * Inflates the given XML resource and adds the preference hierarchy to the current preference * hierarchy. * * @param preferencesResId The XML resource ID to inflate. * @deprecated This function is not relevant for a modern fragment-based PreferenceActivity. */ @Deprecated public void addPreferencesFromResource(int preferencesResId) { requirePreferenceManager(); setPreferenceScreen( mPreferenceManager.inflateFromResource(this, preferencesResId, getPreferenceScreen())); }
/** * Inflates the given XML resource and adds the preference hierarchy to the current preference * hierarchy. * * @param preferencesResId The XML resource ID to inflate. */ public void addPreferencesFromResource(@XmlRes int preferencesResId) { requirePreferenceManager(); setPreferenceScreen( mPreferenceManager.inflateFromResource( mStyledContext, preferencesResId, getPreferenceScreen())); }
/** * Inflates the given XML resource and replaces the current preference hierarchy (if any) with the * preference hierarchy rooted at {@code key}. * * @param preferencesResId The XML resource ID to inflate. * @param key The preference key of the {@link android.support.v7.preference.PreferenceScreen} to * use as the root of the preference hierarchy, or null to use the root {@link * android.support.v7.preference.PreferenceScreen}. */ public void setPreferencesFromResource(@XmlRes int preferencesResId, @Nullable String key) { requirePreferenceManager(); final PreferenceScreen xmlRoot = mPreferenceManager.inflateFromResource(mStyledContext, preferencesResId, null); final Preference root; if (key != null) { root = xmlRoot.findPreference(key); if (!(root instanceof PreferenceScreen)) { throw new IllegalArgumentException( "Preference object with key " + key + " is not a PreferenceScreen"); } } else { root = xmlRoot; } setPreferenceScreen((PreferenceScreen) root); }