5.4.6. activity_settings.xml Layout

In this section, you’ll create the layout for the SettingsActivity (Section 5.8) that will display the SettingsFragment (Section 5.7). The SettingsActivity’s layout will consist of only a LinearLayout containing the GUI for the SettingsFragment. As you’ll see, when you add a Fragment to a layout, the IDE can create the Fragment’s class for you. To create this layout, perform the following steps:

1. In the project’s res folder, right click layout and select New > Android XML File to display the New Android XML File dialog. Because you right clicked the layout folder, the dialog is preconfigured to add a Layout resource file.

2. In the File field, enter activity_settings.xml.

3. In the Root Element section, select LinearLayout and click Finish to create the file.

4. From the Palette’s Layouts section, drag a Fragment onto the design area or onto the LinearLayout node in the Outline window.

5. The preceding step displays the Choose Fragment Class dialog. If you defined the Fragment class before its layout, you’d be able to select the class here. Click Create New... to display the New Java Class dialog.

6. Enter SettingsFragment in the dialog’s Name field, change the Superclass field’s value to android.preference.PreferenceFragment and click Finish to create the class. The IDE opens the Java file for the class, which you can close for now.

7. Save activity_settings.xml.

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

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