5.4.10. preferences.xml for Specifying the App’s Settings

In this section, you’ll create the preferences.xml file that the SettingsFragment uses to display the app’s preferences. To create the file:

1. Right click the project’s res folder, then select New > Folder, in the Folder name field enter xml and click Finish.

2. Right click the xml folder, then select New > Android XML File to display the New Android XML File dialog.

3. In the File text field, enter the name preferences.xml.

4. Ensure that the Resource Type is set to Preference and the Root Element is PreferenceScreen, which represents a screen in which preferences are displayed.

5. Click Finish to create the file. If the IDE displays the raw XML, click the Structure tab at the bottom of the window to configure the preferences.

6. At the left side of the window, select PreferenceScreen, then click Add....

7. In the dialog that appears, select ListPreference, then click OK. This preference will display a list of mutually exclusive options.

8. At the left side of the window, select PreferenceScreen, then click Add....

9. In the dialog that appears, select MultiSelectListPreference, then click OK. This preference will display a list of options in which multiple items can be selected. All of the selected items are saved as the value of such a preference.

10. Select the ListPreference, then configure the properties in Fig. 5.15.

Image

Fig. 5.15 | ListPreference property values.

11. Select the MultiSelectListPreference, then configure the properties in Fig. 5.16.

Image

Fig. 5.16 | MultiSelectListPreference property values.

12. Save and close preferences.xml.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset