Andrews [multilingual and international picture adaptation in different languages]

Introduction:
In some cases, such as the upcoming Olympic Winter Games, we do need to face the user may APP other countries, this time if your APP only support Chinese would be too embarrassing. Ado:

A multi-language adaptation

We use English, for example, in the first of a new \ src \ main under our app \ res directory values-en folder, and then create a xml file called strings in the folder used to store the English string resources. If your name is correct, then the side of a small national flag, as shown below will appear on your strings files. Here we need to note two things:
1. We default folder that the original meaning is implied values-ch, the contents of two strings file folder (name) should be consistent, otherwise the compiler will prompt an error, for example, :

<string name="choose_language">"Choice language"</string>//这个是values-en里的资源
<string name="choose_language">"选择语言"</string>//这个是原来的values文件夹中的资源

2. In case 1, when there are some resources that you think do not need to use the English environment, when placed in the original folder will be error, then we can be caught under the original values ​​in a new file called donottranslate.xml of file, will not need translation resources copied to it. File structure is as follows:

Here Insert Picture Description
3. Before Android 7.0:

 1.1.第一步:
 private void chooseLanguage(Locale locale) {
        Resources resources = getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        Configuration config = resources.getConfiguration();
        config.locale = locale;
        resources.updateConfiguration(config, dm);
        reStart();
    }

    private void reStart() {
         Intent intent = new Intent(this, MainActivity.class);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
         startActivity(intent);
    }

2. After Android 7.0, is quite similar to the other posted a blogger (tort deleted)
Here Insert Picture Description

II. Multi-language adaptation picture

Pictures and text operations are substantially similar, just keep two folders of pictures resources of the same name can be. But the system will select the two folders according to language resources for pictures, when our environment is in English, if English is not a picture file folder needed, will be replaced with a Chinese folder picture.
Here Insert Picture Description

Published 47 original articles · won praise 15 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_41525021/article/details/103355167