To test the app in Spanish, you must change the language settings in the Android emulator (or on your device). To do so:
1. Touch the home () icon on the emulator or on your device.
2. Touch the launcher () icon, then locate and touch the Settings app () icon.
3. In the Settings app, scroll to the PERSONAL section, then touch Language & input.
4. Touch Language (the first item in the list), then select Español (España) from the list of languages.
The emulator or device changes its language setting to Spanish and returns to the Language & input settings, which are now displayed in Spanish.
Next, run the Welcome app from the IDE, which installs and runs the internationalized version. Figure 2.27 shows the app running in Spanish. When the app begins executing, Android checks the AVD’s (or device’s) language settings, determines that the AVD (or device) is set to Spanish and uses the welcome
, android_logo
and deitel_logo
string resources defined in res/values-es/strings.xml
in the running app. Notice, however, that the app’s name still appears in English in the action bar at the top of the app. This is because we did not provide a localized version of the app_name
string resource in the res/values-es/strings.xml
file. Recall that when Android cannot find a localized version of a string resource, it uses the default version in the res/values/strings.xml
file.
Modifying the names of resources can lead to runtime errors. Android uses the default resource names when loading localized resources. When you create a localized resource file, be sure to modify only the values of the resources, not their names.