Android builds its own personalized application (1): Analysis and overview of mainstream application skin-changing methods

Source: Internet
Author: User
Tags format definition

The Android platform api does not specifically provide a simple mechanism for skin replacement. This may be because foreign software focuses more on functions and ease of use and is not popular with skin replacement. The system does not provide direct support and can only be studied on its own.


It can be considered as a dynamic replacement of resources (text, color, font size, images, layout files ......). This can be done with dynamic Settings Using programming languages, such as using the setBackgroundResource, setTextSize, setTextColor, and other functions of View. However, it is impossible for every activity to replace all the controls on the page by calling these functions. Such program code is difficult to maintain and expand, it also violates the principle of UI and code separation (UI layout in android development is based on xml files ). Generally, skin resources are provided outside the main program apk to reduce the size of the main program and facilitate new skin extension at any time.


Simply put, the software skin includes icons, fonts, la S, interactive styles, etc. Skin replacement is to replace part or all of the resources included in the skin.

 

 

Mainstream application skin Replacement Methods:


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. before writing this series, I also referred to some other people's summary. the knowledge points are scattered, So I sorted them out and further optimized and expanded them. of course, due to limited energy, I only wrote about the implementation of the main function in some skin replacement methods. if there are errors or not detailed details, I hope you can give your comments or expand them on your own.

For the mainstream implementation methods mentioned in this article, I will provide specific code for explanation in the next article. I will give a general overview here.


Currently, the mainstream skin replacement functions can be divided into several implementation methods,


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 relatively simple compared to the following ones.

If your programs and resources are small, you can put enough skin Resources in the main program apk.

Typical applications: the QQ space skin swap function on Apad actually only changes the background of the Activity or resources.

 


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.

Typical application: the skin downloaded by moji weather is a zip compressed package. During the application, the skin resources are released to the directory of the moji weather application, when skin is changed, the new skin resources will replace the old skin resources. Each time the resources are loaded, the pictures are read from the hard drive of the mobile phone. The names of these image resources are consistent with those in the program, once these resources cannot be found, you can find them in the default system.

This implementation directly reads external resource files and replaces the background resources on the Interface displayed by the code when the program is running.

The advantage of this method is that the format definition of skin resources can be zip or custom at will, as long as the resources can be parsed in the program, the disadvantage is that the file needs to be read and parsed, resulting in poor efficiency.

3) The skin resources exist in the main program and other APK, that is, the APK is split. this is similar to the relationship between browsers and plug-ins. this method is required when you need to expand your application ., this is not only reflected in the skin-changing APK.


Typical application: Implement QQ mobile phone skin replacement

QQ's skin is a non-interface APK application. The resources in this skin application are named the same as those in the main program, through the main program and skin program sharing process, the main program can access the resources in the skin program. When the program is running, the Code displays the specified skin resources, the disadvantage is that the complex skin logic used for each activity in the main program is that the efficiency is relatively fast, and the application has good scalability and reduces program coupling. other similar extension functions can be implemented using this method.

 


4) The official website provides skin preparation tools or methods for users to make skin:

There are two possible cases:

1. The main Application List is a GridView. You can directly replace it by selecting the background color and button style in the settings.

2. There is a visual tool with a wizard. You only need to find some images and replace the font of the modified text. You can upload your own skins and download them from other users. generally, it is in the. ZIP format. The extension can be customized by the company's requirements. for example, the moji weather skin extension is mja, And the sogou input method's skin extension is sga. Their file formats are actually zip. The subsequent application is similar to the second skin replacement method.


This method has the following advantages: it gives users a sense of participation and a high degree of freedom. You can customize the skin of the Software Based on your preferences.



5) rewrite the SDK Resource class:

At an event in CMDN in February 29 this year, Dong Hongguang, a Xiaomi MIUI system engineer, delivered a keynote speech on the underlying skin Replacement Technology of the Android MIUI system. He mentioned that Xiaomi subject replacement is a Resource class for SDK rewriting, this method requires familiarity with the FrameWork layer of the Android system, so the implementation is complicated and takes a lot of effort to study.

Here we provide some ideas:


In the Android system, resources mainly refer to images and MP3 files, and are all elements contained in the user UI. Google separated the UI and logic code when designing the Android system: the interface design is described in XML format, and the specific program and application logic are implemented through code; front-end engineers are only responsible for the design and architecture of HTML and CSS, while back-end engineers are dedicated to JSP and Java code execution.

What is the position of resource access in the Android performance architecture? When developing androiddevelopment, developers often use frameworkworker Resource Packages framework.jarand framework-res.apk, as well as the core Resource-related component "Resource Manager" file system.

APK is a simple file format and a compressed file package. You can decompress the package to release the APK file. First, you need the Meta INF, Manifest, and RES directories of the APK. Some applications that contain image resources also use Layout when resources are released.

When installing the file, the system extracts and decompress the file and places it in the Dalvik Cache. The cache contains many dex files. when you open an application, the system automatically loads the corresponding classes. During the loading process, if the system needs to access the APK, it needs to be decompressed, which usually leads to low efficiency. If the dex file is put into the Dalvik Cache, the loading efficiency can be greatly improved.

Each process has a shared class and shared resource about the Framework, but there is only one system-level resource in the physical memory space. Framework classes and resources are read-only. At the beginning of Android operating system design, there is no virtual memory and swap-in/out mechanism on the hard disk. Therefore, it is very important to save memory space.

 


 

Related Article

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.