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

(gtxtreme123) #1

Prioritizing alternative resources


Prioritizing alternative resources


Given the many types of configuration qualifiers for targeting resources, there may be times when the
device configuration will match more than one alternative resource. When this happens, qualifiers are
given precedence in the order shown in the list above.


To see this prioritizing in action, let’s add another alternative resource to CriminalIntent – a longer
English version of the crime_title_hint string resource – to be displayed when the current
configuration’s width is at least 600dp. The crime_title_hint resource is displayed in the crime title
edit text before the user enters any text. When CriminalIntent is running on a screen that is at least
600dp (e.g., on a tablet, or perhaps in landscape mode on a smaller device), this change will display a
more descriptive, engaging hint for the title field.


Create a new string resource file and place it in a new values-w600dp directory (-w600dp will match
any device where the current available screen width is 600dp or more, meaning a device may match
when in landscape mode but not in portrait mode). Follow the same steps from the section called
Localizing Resources to create the values resource file, but select Screen Width in the Available
qualifiers list and click the >> button to move Screen Width to the Chosen qualifiers section. For the
rest of the fields, enter the values shown in Figure 18.11.


Figure 18.11  Adding strings for a wider screen

Free download pdf