Design your application to work in any locale

You cannot assume anything about the device on which a user will run your application. The device might have hardware that you were not anticipating, or it might be set to a locale that you did not plan for or that you cannot test. Design your application so that it will function normally or fail gracefully no matter what device it runs on.

Important: Make sure that your application includes a full set of default resources.

Make sure to include res/drawable/ and a res/values / folders (without any additional modifiers in the folder names) that contain all the images and text that your application will need.

If an application is missing even one default resource, it will not run on a device that is set to an unsupported locale. For example, the res/values/strings.xml default file might lack one string that the application needs: When the application runs in an unsupported locale and attempts to load res/values/strings.xml, the user will see an error message and a Force Close button. An IDE such as Eclipse will not highlight this kind of error, and you will not see the problem when you test the application on a device or emulator that is set to a supported locale.

For more information, see Testing for Default Resources. Design a flexible layout

If you need to rearrange your layout to fit a certain language (for example German with its long words), you can create an alternate layout for that language (for example res/layout-de/main.xml). However, doing this can make your application harder to maintain. It is better to create a single layout that is more flexible.

Another typical situation is a language that requires something different in its layout. For example, you might have a contact form that should include two name fields when the application runs in Japanese, but three name fields when the application runs in some other language. You could handle this in either of two ways:

• Create one layout with a field that you can programmatically enable or disable, based on the language, or

• Have the main layout include another layout that includes the changeable field. The second layout can have different configurations for different languages.

0 0

Post a comment