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

(gtxtreme123) #1

Testing Alternative Resources


Because there are multiple values still in the running, Android keeps stepping down the qualifier
list. When it reaches available width, it finds one directory with an available width qualifier and two
without. It rules out values and values-es/, leaving only values-es-w600dp/:


Device Configuration App values for crime_title_hint


  • Language: es (Spanish) • values (not width specific)

  • Available height: 411dp • values-es (not width specific)

  • Available width: 731dp • values-es-w600dp (best match)

  • (etc.) • values-w600dp (not language specific)


Thus, Android uses the resource in values-es-w600dp/.


Testing Alternative Resources


It is important to test your app on different device configurations to see how your layouts and other
resources look on those configurations. You can test on devices both real and virtual. You can also use
the graphical layout tool.


The graphical layout tool has many options for previewing how a layout will appear in different
configurations. You can preview the layout on different screen sizes, device types, API levels,
languages, and more.


To see these options, open fragment_crime.xml in the graphical layout tool. Then try some of the
settings in the toolbar shown in Figure 18.14.


Figure 18.14  Using graphical layout tool to preview various device configurations


You can ensure that you have included all of the necessary default resources by setting a device to a
language that you have not localized any resources for. Run your app and put it through its paces. Visit
all of the views and rotate them. If the app crashes, check Logcat for a “Resource not found” message
to track down the missing default resource. Be on the lookout for non-crashing errors, such as the
problem of resource IDs displaying instead of strings that we discussed earlier in this chapter.


Before continuing to the next chapter, you may want to change your device’s language back to English.


Congratulations! Now your CriminalIntent app can be enjoyed fully in both Spanish and English.
Crimes will be logged. Cases will be solved. And all in the comfort of your user’s native language (so
long as that is either Spanish or English). Adding support for more languages is simply a matter of
adding additional qualified strings files.

Free download pdf