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

(gtxtreme123) #1

Chapter 18  Localization


Screen density works differently


The exception to providing default resources is for screen density. A project’s drawable directories are
typically qualified for screen density with -mdpi, -xxhdpi, etc., as you have seen. However, Android’s
decision about which drawable resource to use is not a simple matter of matching the device’s screen
density or defaulting to an unqualified directory if there is no match.


The choice is based on a combination of screen size and density, and Android may choose a drawable
from a directory that is qualified with a lower or higher density than the device and then scale
the drawable. There are more details in the docs at developer.android.com/guide/practices/
screens_support.html, but the important point is that putting default drawable resources in res/
drawable/ is not necessary.


Checking string coverage using Translations Editor


As the number of languages you support grows, making sure you provide a version of each string
for each language becomes more difficult. Luckily, Android Studio provides a handy Translations
Editor to see all of your translations in one place. To launch the Translations Editor, right-click
on one of the strings.xml files in the project tool window and select Open Translations Editor.
The Translations Editor displays all of the app’s strings and the translation status for each of the
languages your app currently provides any qualified string values for. Since crime_title_label and
crime_report_subject are commented out, you will see those field names in red (Figure 18.7).


Figure 18.7  Using the Translations Editor to check your string coverage


(Now it is time to uncomment both crime_title_label and crime_report_subject before moving
on. You can uncomment out a single line by clicking on the line and then pressing Command+/ [Ctrl+/]
again.)

Free download pdf