Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested preferences.xml

Is it somehow possible to include one preferences.xml into another, like it can be done for layouts with the <include /> tag?

Let's say:

<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen      xmlns:android="http://schemas.android.com/apk/res/android">     <PreferenceScreen          android:title="@string/pref_group_title_visual">         <include              preferences_filename="xml/pref_visual"/>     </PreferenceScreen> ... 
like image 878
GrAnd Avatar asked Mar 15 '11 16:03

GrAnd


People also ask

How are preferences saved to an XML file?

Preference hierarchy specified in an XML You should just set up a new folder call it xml and the create preference. xml and save it there. There are a large number of example preferences shown in the preference.

What is Preferencescreen in Android?

Represents a top-level Preference that is the root of a Preference hierarchy. A PreferenceActivity points to an instance of this class to show the preferences. To instantiate this class, use PreferenceManager#createPreferenceScreen(Context) .

Where are preferences in Android Studio?

From the menu bar, click File > Settings (on macOS, click Android Studio > Preferences).

What is PreferenceFragmentCompat?

A PreferenceFragmentCompat is the entry point to using the Preference library. This Fragment displays a hierarchy of Preference objects to the user. It also handles persisting values to the device. To retrieve an instance of android.


2 Answers

Solution here it is to inflate both preference files from PreferencesActivity. For example:

    addPreferencesFromResource(R.xml.options);     addPreferencesFromResource(R.xml.additional_options); 
like image 84
soul Avatar answered Oct 02 '22 20:10

soul


The solution soul shows works. It can be expanded to only show preferences if you're the developer using an unsigned version of the app ;)

addPreferencesFromResource(R.xml.options); addPreferencesFromResource(R.xml.additional_options); if (BuildConfig.DEBUG) {     addPreferencesFromResource(R.xml.developer_options); } 

I created a blog post regarding this issue and have a complete working code example available for download. http://androidfu.blogspot.com/2012/05/developer-debug-with-nested-preferences.html

like image 20
Bill Mote Avatar answered Oct 02 '22 20:10

Bill Mote