Android Application resource-localization (1)

Source: Internet
Author: User

Android runs on many devices in many regions. To meet the needs of most users, the application should use text, audio files, numbers, currency symbols, and graphics that match the application's region.

This document describes the best practices for localization of Android applications. This principle applies to any IDE development tools you are using, such as eclipse with ADT and ant-based tools.

First, you must understand Java programming knowledge, and be familiar with the resource loading process of Android, as well as the declaration methods of user interface elements in XML. In terms of development, you must master the activity life cycle and general principles of internationalization and localization.

It is a good practice to use the android resource framework to isolate the localized appearance of applications from core Java functions as much as possible.

1. You can put the user interface content of most or all applications into the resource file;

2. User Interface Behavior and other processing are driven by Java code. For example, if the data you enter needs to be formatted or sorted by region, you must use Java code to program and process the data.

Summary: Resource switching in Android

Resources are text strings, la S, sounds, graphics, and other static data required by Android applications. An application can contain multiple resource sets, each of which is customized for different device configurations. When you run an application, Android automatically selects and loads the resources that match the device.

When writing an application, you need to create a set of default resources, plus optional resources for different regions.

When a user runs an application, the android system selects to load the appropriate resources based on the region.

When writing an application, you must create default and optional resources for the application. For these created resources, you need to put them in the Res/directory, the files in the subdirectory of a specific name.

Why is the default resource important?

When an application runs in a language environment that does not provide specific language text, Android loads the default string from Res/values/strings. xml. If the default file does not exist or the string required by the application is missing, the application will not run and an error will be displayed. The following example shows the problem that occurs when the default text file is incomplete:

The Java code of the application only references two strings: text_a and text_ B. This application contains the local resource files (RES/Values-en/strings. XML) of text_a and text_ B defined in English ). The application also contains a default resource file (RES/values/strings. XML), which contains the definition of text_a, but does not define text_ B.

1. There may be no problems during application compilation. If a resource error occurs in an IDE like Eclipse, it does not report any errors.

2. when an application is started on a device with an English language environment, the application runs correctly because Res/Values-en/strings. XML contains the required text string.

3. However, when the application starts on a device with a language other than English, the user will see an error message and the force close button.

To prevent this, make sure that the Res/values/strings. xml file exists and each required string is defined. This applies to all types of resources, not just strings. You need to create default resource files for all types of resources required by the application, including layout resources, plotting resources, and animation resources.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.