Traditional Culture Encyclopedia - Weather forecast - How to change the skin of Android application? .

How to change the skin of Android application? .

There are many domestic softwares that support skin customization, which is also a big difference from foreign softwares. Foreign users pay attention to social networking, email and other functions, while domestic users pay attention to music, novels, skin and other functions. This course will explain how Android applications can achieve skinning function. Software skins can be divided into three functions: 1) There are multiple skins built into the software, and users cannot add or modify them; The degree of freedom is the lowest, and software implementation is the easiest compared with the latter two. 2) The official skin is available for download, and users can use the downloaded skin; Users can choose to download their favorite skin, and some players will crack the customization method of skin, make their own skin for use, or upload it online for everyone to use. 3) Provide official skin making tools or methods, and users can make their own skin. this

This method gives users a sense of participation and a high degree of freedom. Users can customize the skin of the software according to their own preferences. Some software official website provides tools or methods for skin customization. I suggest that it is better to have a visualization tool with a wizard. use

Users only need to find some pictures and modify the font replacement of the text themselves. Users can upload homemade skins, provide them for other users to download, and earn some virtual money or prizes. This kind is usually played.

The package is inside. Zip format. Extensions can be customized by various companies, and it is most convenient to export them directly if there are production tools. First of all, we must make clear the definition of skin exchange. Software skin includes icons, fonts, layouts, interactive styles, etc. Changing skin means changing some or all of the resources contained in the skin. From the perspective of software implementation, the essential difference between the three skins mentioned above lies in whether the skin is built into the application. For the built-in implementation, it is relatively simple, as long as several sets of skins are designed for users to choose in the process of developing applications. The knowledge used here does not exceed the Android foundation, so I won't explain it in detail. This lesson focuses on how to separate skin from application. skin

Skin generally contains multiple files, such as pictures, configuration files, etc. Scattered files are not conducive to transmission and use, so it is better to pack them. Zip format is generally selected as the packaging format. There are two situations here, one is apk, such as

AdwLauncher, whose desktop skin format is apk;; The other is custom extension, such as the skin extension of ink weather is mja, and the skin extension of sogou input method is sga.

The file format of is actually zip. Explain it separately below. The problem of 1.APK format now becomes how the application reads the resources in another apk. In the android system, apks can read data from each other on the condition that they have the same signature and the attribute values of android:sharedUserId configured in the AndroidManifest.xml file are the same, then two apks run in the same process and can access any data from each other. The method is as follows: 1) Configure the AndroidManifest.xml of the application and the skin program, for example: Android: shared userid = "org.yuchen" 2) The file names of the skin with the same function in apk should be consistent, for example: the background image path of the application: \ skin demo \ RES \ Drawable-hdpi \ BG. png Then the path of the background image file in the skin apk should also be: customskin \ res \ drawable-hdpi \ bg.png3). You can access any resource in org.yuchen.customskin through the returned Context object. For example, bg.png in skin apk is obtained by applying apk, and drawable drawable = context. getresources()。 getdrawable(r . drawable . BG); In this way, references to pictures are obtained, and other xml resource files are obtained in a similar way. 2. The skin technology of zip format with custom extension lies in how to read the resources in zip file and the storage strategy of skin file. square

Case: If the software reads the skin file on the SD card every time it starts, the speed will be slower. A better way is to provide a skin setting interface, which skin the user chooses, and then extract the skin file.

To "/data/data/[package

Name]/skin "path, so you don't need to read it across memory, which is faster, and you don't need to read it in the zip compressed package every time. It doesn't depend on the files in the SD card, even if the skin compressed package file is in.

It doesn't matter if you delete it. Implementation method: 1. Prompt the user to copy the skin file to the specified path of the SD card with the help of software or official website. 2. Provide skin setting interface in the software. It can be in the menu or in the settings. You can refer to ink, sogou input method, QQ and other software that supports skin changing. 3. Load the skin file in the specified path, read the thumbnail, display it in the skin setting interface, and decompress the skin file selected by the user to the "/data/data/[ package name ]/skin" path. 4. Give priority to reading the resources under the path "/data/data/[ package name ]/skin/" in the software. If not, please use the resources in apk.

fresh water