This series of special training applies to: Beginner Android programmers, that is, j2se basics and Android beginners. J2se refers to mastering the Java syntax. It doesn't matter if the New syntaxes 1.5 and 1.6 are not fully mastered. Understand basic object-oriented ideas, write simple j2se programs, master basic debugging methods, and be familiar with swing. Android beginners refer to mastering the use of activity, service, broadcastreceiver, intent, SQLite, and UI components. You can refer to examples to compile simple Android applications.
Let's take a look at the effect:
The purpose of this course is to learn about the skin replacement solution and implementation, and master the advantages and disadvantages of different skin replacement solutions and their application scenarios.
I hope you can learn a certain skill and practice more. It is best to draw a similar picture to understand the ideas and methods for problem solving.
I will explain the principles and key technical points of implementation. I may not explain the details, optimization, or elementary content unrelated to the course subject. This is free training with limited energy. For the time being, it is only possible to make normal and outstanding. If you are already excellent, teach me. No entry-level training is provided.
Many software products in China support skin customization, which is also one of the major differences with foreign software. foreign users focus on social networking and email functions, while domestic users focus on music, novels, skin and other functions, this course explains how to enable skin replacement for Android applications.
The software skin change function can be divided into three types:
1) The software has multiple built-in skins and cannot be added or modified by users;
With the lowest degree of freedom, software implementation is easier than the last two.
2) The official website provides skin for download. Users can use the downloaded skin;
Users can choose to download their favorite skins. Some players will crack the custom method of skin, use the skin by themselves, or upload it to the Internet for everyone to use.
3) The official website provides skin preparation tools or methods for users to make skin.
This method gives users a sense of participation and a high degree of freedom. You can customize the skin of the Software Based on your preferences. Some software official websites provide skin customization tools or methods. I suggest you have a visual tool with a wizard. You only need to find some images and replace the font of the modified text. Users can upload their own skins, provide downloads from other users, and earn some virtual currency or prizes. This is generally in the. ZIP format. Extensions can be customized by companies. If there is a production tool, it is most convenient to export it directly.
First, we need to understand the definition of skin replacement. The software skin includes icons, fonts, la S, and interactive styles. Skin replacement is to replace all or part of the skin.
The three skins mentioned above, in terms of software implementation, are essentially differentIs the skin built into the application?. The built-in implementation is relatively simple. You only need to design several skin sets during application development for users to choose from. The knowledge used here is no more than the basic knowledge of Android.
This course focuses on how to separate skin from applications.
The skin usually contains multiple files, such as sample files and configuration files. Scattered files are not conducive to transmission and use. It is best to pack them. Generally, the package format is zip. There are two cases: APK, for example, adwlauncher, whose desktop skin format is an APK, and custom extension, for example, moji weather skin extension is mja, the skin extension of sogou input method is SGA, and their file formats are actually zip.
Next we will explain it separately.
Yi.apk format
Now the question is how an application reads resources from another APK.
In Android systems, apks can read data from each other only if they have the same signature and androidmanifest. if the Android: shareduserid attribute value configured in the XML file is the same, the two apks run in the same process and can access any data from each other.
The method is as follows:
1) configuration in androidmanifest. xml of applications and skin programs
For example, Android: shareduserid = "org. yuchen"
2) the file name must be the same as the skin file name of the same function in the application APK.
Example: app background image path:/skindemo/RES/drawable-hdpi/bg.png
The path of the background image file in the skin APK should also be:
Customskin/RES/drawable-hdpi/bg.png
3) how to access resources
[Java]View
Plaincopyprint?
- Context context = createpackagecontext ("com. yuchen. customskin", context. context_ignore_security );
Obtain the context corresponding to org. yuchen. customskin, and access any resources in org. yuchen. customskin through the returned context object.
For example, to apply apkto bg.png in apk,
- Drawable = context. getresources (). getdrawable (R. drawable. bg );
In this way, the image reference is obtained, and other XML resource files are obtained in a similar way.
2. Custom extension ZIP format skin
The technical point is how to read the resources in the ZIP file and the storage policy of the skin file.
Solution: if the software reads the skin files on the SD card every time it starts, the speed will be slow. It is better to provide a skin setting interface. If you select a skin, extract the skin file to the "/data/[package name]/skin" path, in this way, it does not need to be read across memory, which is fast, and does not need to be read from the zip package every time. It does not depend on the files in the SD card, even if the file in the skin package is deleted.
Implementation Method:
1. You are prompted to copy the skin file to the path specified by the SD card with the help of the software or help from the official website.
2. Provide the skin setting interface in the software. It can be in the menu or in the settings. You can refer to moji, sogou input method, QQ, and other software that supports skin replacement.
3. load the skin file in the specified path, read the thumbnail, and display it on the skin settings page, decompress the selected skin file to the "/data/[package name]/skin" path.
4. The software preferentially reads Resources in the "/data/[package name]/skin/" path. If not, use the resources in the APK.
Source code and Q & A are all in the QQ group.
From: http://blog.csdn.net/suiyc/article/details/6329212