Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 18  Localization


Add a longer value for crime_title_hint to values-w600dp/strings.xml.


Listing 18.4  Creating alternative string resource for wider screen


(values-w600dp/strings.xml)




Enter a meaningful, memorable title for the crime.


The only string resource you want to be different on wider screens is crime_title_hint. That is why
crime_title_hint is the only string you specified in values-w600dp. Alternatives for string resources
(and other values resources) are provided on a per-string basis, so you do not need to duplicate strings
when they are the same. Those duplicated strings would only end up being a maintenance hassle down
the road.


Now you have three versions of crime_title_hint: a default version in values/strings.xml, a
Spanish alternative in values-es/strings.xml, and a wide-screen alternative in values-w600dp/
strings.xml.


With your device’s language set to Spanish, run CriminalIntent and rotate to landscape (Figure 18.12).
The Spanish language alternative has precedence, so you see the string from values-es/strings.xml
instead of values-w600dp/strings.xml.


Figure 18.12  Android prioritizes language over available screen width


If you like, you can change your settings back to English and run again to confirm that the alternative
wide-screen string appears as expected.

Free download pdf