In the resulting Create New Class dialog, name the class ToolbarFragment and click on OK to create the new class. From the resulting menu, select the New -> Java Class option. Add a class for this purpose to the project by unfolding the app -> java folder in the Project tool window and right-clicking on the package name given to the project when it was created (in this instance ). In addition to a user interface layout, a fragment also needs to have a class associated with it to do the actual work behind the scenes. With the layout for the first fragment implemented, the next step is to create a class to go with it. Upon completion of these steps, the user interface layout should resemble that of Figure 30-2: Select the hardcoded text warning, click the Fix button and assign the string to a resource named change_text. Once the changes have been made, switch the Layout Editor tool back to Design mode and click on the warning button in the top right-hand corner of the design area. Switch the Layout Editor to Text mode and modify the XML so that it reads as outlined in the following listing to add three new view elements to the layout: The new resource file will appear within the Layout Editor tool ready to be designed. In the resulting dialog, name the layout toolbar_fragment and change the root element to RelativeLayout before clicking on OK to create the new resource file. Once located, right-click on the layout entry and select the New -> Layout resource file menu option as illustrated in Figure 30-1: This user interface will, of course, reside in an XML layout file so begin by navigating to the layout folder located under app -> res in the Project tool window. The next step is to create the user interface for the first fragment that will be used within our activity.
0 Comments
Leave a Reply. |