Adding Project Resources

The Been There, Done That! project requires some additional resources. Specifically, you need to add a Layout file for each activity and a text string for each activity name, and you need to change the application icon to something more appropriate.

Adding String Resources

First, you modify the strings.xml resource file. You delete the hello string and create six new string resources—one for each screen. For example, you should create a string called help with a value of "Help Screen". When you are done, the strings.xml file should look like this:

<?xml version="i.0" encoding="utf-8"?> <resources> <string name="app_name">Been There, Done That!</string> <string name="help">Help Screen</string> <string name="menu">Main Menu Screen</string> <string name="splash">Splash Screen</string> <string name="settings">Settings Screen</string> <string name="game">Game Screen</string> <string name="scores">Scores Screen</string> </resources>

Adding Layout Resources

Next, you need layout files to match each activity you will be creating. First, you rename the main.xml layout splash.xml. Then you copy the splash.xml file five more times, resulting in one layout for each activity: game.xml, help.xml, menu.xml, scores.xml, and settings.xml.

You may notice that there is an error in each Layout file. This is because the TextView control in the layout refers to the @string/hello string, which no longer exists. For each layout file, you need to use the Eclipse layout editor to change the String resource loaded by the TextView control. For example, game.xml needs to replace the reference to @string/hello with the new string you created called @string/game. Now when each layout loads, it displays the screen it is supposed to represent.

Adding Drawable Resources

While you are adding resources, you should change the icon for your application to something more appropriate. Starting with a nice public domain image of Earth from NASA, you can create a 48x48 pixel PNG file called quizicon.png and add this resource file to the /drawable resource directory. Then you can delete the icon.png file used by default.

Did you Know?

0 0

Post a comment