Android to build your own personalized application (i): Analysis and overview of application skin-changing mainstream methods

Source: Internet
Author: User
Tags format definition

The Android platform API does not intentionally provide a set of simple mechanisms for skin rejuvenation, which may be foreign software that is more feature-oriented and easy to use, not popular for skinning. The system does not provide direct support and can only be researched on its own.

To change the skin, you can think of dynamic replacement resources (text, color, font size, pictures, layout files ...). )。 This can be done using a programming language for dynamic settings, such as Setbackgroundresource, Settextsize, SetTextColor, and so on, with view. However, it is not possible for us to change all the controls in the page by invoking these functions in each activity, which is difficult to maintain, extend, and violate the principles of UI and Code separation (the UI is laid out in an XML file in Android development). Typically, skin resources are provided outside the main program apk to reduce the size of the main program and to provide new skin extensions at any time.

In simple terms, software skins include icons, fonts, layouts, interactive styles, and so on, changing the skin to replace some or all of the resources.

main application Skin changing methods :

There are many domestic software support skin customization, which is one of the major differences with foreign software, foreign users focus on social, mail and other functions, domestic users pay attention to music, novels, skin and other functions. Before I wrote this skin-changing series, I also referred to some of the other people's summaries. The knowledge points are scattered, so I organize and further optimize and expand them. Of course, due to limited energy, part of the skin-changing methods I have only written the main function of the implementation. If there is a mistake or not enough detail, we would like to make comments or expand on our own.

As to the main implementation methods mentioned in the following article, I will provide the specific code to explain, this time first to do a general overview.

At present, the main function of the skin-changing can be divided into several implementation methods,


  1) The software contains multiple skins, which cannot be added or modified by the user:

The lowest degree of freedom, the software implementation relative to the following several relatively simple.

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

Typical application: Tablet computer apad on the QQ space of the skin function, actually just change the background of the activity, or this part of the resources.

  2) The official skins are available for download and users can use the downloaded skins:


Users can choose to download their favorite skin, some players will crack the skin of custom methods, do their own skin use, or upload to the internet for everyone.

Typical application: Ink weather download of the skin is a zip format of the compressed package, in the application of the skin resources released to the Ink Weather application directory, the replacement skin of the skin resources will replace the old skin resources each time the load is from the phone hard disk to read pictures, The names of these picture resources are consistent with the names of the resources in the program, and once these resources are not found, you can choose to find them by default in the system.

This implementation is to directly read the external resource file, when the program runs through the code to display the replacement interface of the background resources.

The advantage of this way is: the skin resource format definition is arbitrary can be zip or can be a custom format, as long as the program can resolve to the resources on the line, the disadvantage is to read and parse the file, resulting in poor efficiency.

3) Skin resources exist in the main program and the like APK, that is, the implementation of the APK split. This is similar to the browser's relationship with plugins. When considering an application that needs to be extended, it needs to be implemented in this way, not just in the skin-changing apk.

Typical application: Mobile phone QQ skin change Realization Way

QQ Skin is a no interface apk application, this skin application resources and the main program resource naming consistent, through the main program and the skin program sharing process to achieve the main program of the skin Program access to resources, in the program run through the code to display the specified skin resources, The disadvantage is that in the main program each activity to increase the complexity of the use of which skin logic, the advantage is more efficient, and the application has a good extensibility, reducing the coupling of the program. Including other similar extensions, can be implemented in this way.

  4) The official skin production tools or methods, the user can self-made skin:

It is broadly divided into two situations:

1. The application master list is a GridView, and the user can choose the color of the background and the style of the button in the settings. You can replace them directly.

2. Another is a tool with a visual guide. Users only need to find some of their own pictures, modify the font of the text to replace it. Users can upload homemade skins and provide other users with the download. Typically packaged in. zip format, the extension can be customized by company requirements. For example, ink weather skin extension is mja, Sogou input Method's skin extension is SGA, their file format is actually zip. The subsequent application is similar to the second skin-changing method.

The advantages of this approach are: the user has a sense of participation, high degree of freedom. Users can customize the skin of the software according to their preferences.


5) Rewrite the SDK resource class:

At an event in Cmdn this February 29, Xiaomi MIUI system engineer Dong Hongguang published a keynote speech on the Android system miui underlying skin-changing technology, referring to the Xiaomi theme change as the resource class for rewriting the SDK. This approach requires familiarity with the framework layer of the Android system, so it is more complex and expensive to study.

Here are a few ideas:

In Android, resources mainly refer to pictures and MP3 types of files, and all the elements contained in the user UI. Google in the design of the Android system, the UI interface and logic code to separate: the interface design is described in XML form, the specific program and application logic through the code to achieve; front-end engineers are only responsible for HTML and CSS design and architecture, Back-end engineers are specifically considering JSP and Java code execution.

What is the status of resource access in the Android performance architecture? In Android development, developers often use the resource bundles provided by the framework Framework.jar and framework-res.apk, as well as the components associated with the core resources "Resource Manager" file system.

The APK itself is a simple file format and is also a zipped file package. The APK file can be released by unpacking the package: The original data meta INF, manifest, and res directories of the APK are required first. Part of the application that contains the image resources will also use layout when the resource is released.

When the file is installed, the file is removed, decompressed, and placed in the Dalvik cache. There are many Dex files under the cache, and the system automatically loads the appropriate classes when the user opens the app. During the loading process, the system needs to access the APK, which needs to be decompressed, which often leads to inefficiency. If you put the Dex file into the Dalvik cache, you can make the load much more efficient.

Each process has a shared class and shared resources about the framework, but only one copy of the system-level resources in the physical memory space. The framework classes and resources are read-only, and the Android operating system is not designed to have virtual memory and swap-out mechanisms for hard disks, so saving memory space is a very important task.

For details of this event, please see the following address:

http://www.csdn.net/article/2012-03-01/312643

Android to build your own personalized application (i): Analysis and overview of application skin-changing mainstream methods

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.