Listing 38 Externalized strings for the Restaurant Finder application stringsxml

<?xml version= "1.0" encoding= "utf-8"?> <resources>

<string name="app_name_criteria">RestaurantFinder - Criteria</string> -<string name="app_name_revie¥s">RestaurantFinder - Reviews</string> <string name="app_name_revie¥">RestaurantFinder - Review</string> <string name= "app_short_name">Restaurants</string>

Using a string

<string name= "menu_get_reviews">Get reviews</string> element with a

<string name= "'menu web review">Get full review</string> _ ^ .. ^ A

name attribute

<string name="menu_map_review">Map location</string> <string name= "'menu_call_review">Call restaurant</string> <string name= "'menu_change_criteria">Change review criteria</string> <string name="menu_get_next_page">Get next page of results</string>

<string name= "'intro_blurb_criteria">Enter review criteria</string> <string name="intro_blurb_detail">Review details</string>

. . . remainder omitted for brevity


As is evident from the strings.xml example, this is very straightforward. This file uses a <string> element with a name attribute O for each string value you need. We have used this file for the application name, menu buttons, labels, and alert validation messages. This format is known as simple value in Android terms. This file is placed in source at the res/values/strings.xml location. In addition to strings, colors and dimensions can be defined in the same way.

Dimensions are placed in dimens.xml and defined with the <dimen> element: <dimen name=dimen_name>dimen_value</dimen>. Dimensions can be expressed in any of the following units:

■ density-independent pixels (dp)

■ scale-independent pixels (sp)

Colors can be defined in colors.xml and are defined with the <color> element: <color name=color_name>#color_value</color>. Colors values are expressed in RGB codes. Color and dimension files are also placed in the res/values source location.

Although we haven't defined separate colors and dimensions for the RestaurantFinder application, we are using several styles, which we referenced in listing 3.7. The style definitions are shown in listing 3.9. This is where we move beyond a simple value layout to a specific style XML structure (although styles are still placed in source in the res/values directory, which can be confusing).

0 0

Post a comment