An analysis of two ways to realize skin-changing in Android _android

Source: Internet
Author: User

This paper analyzes the two ways to realize the skin-changing of Android. Share to everyone for your reference, specific as follows:

Here to understand the implementation of the skin and different options and the use of the occasion.

One, from the functional division

1 software built-in multiple skin, users can not modify;

2 The official provides the skin downloading, the user uses the downloading skin;

3 The official provision of skin-making tools or methods, user-made skin.

Second, skin definition

Software skin includes icons, fonts, layouts, interactive styles, and so on, changing the skin is to replace some or all of the resources included.

Third, skin and app separation

1 Packing skin files

The default format is APK. For example launcher, its desktop skin format is a apk;

The custom format is zip. For example, ink weather skin extension is mja, Sogou method of skin extension is SGA, their file format is actually zip.

Iv. Resource access

1) apk format

The condition for reading data between apk is that it has the same signature and the Androidmanifest.xml configuration Android:shareduserid has the same property value, so that two apk run in the same process, they can access the data.

The method is as follows:

A the application and the skin program in the Androidmanifest.xml configuration

For example:

Copy Code code as follows:
Android:shareduserid= "Com.zj"

b File and application apk the same function of the skin file name to be consistent

For example: The application's background picture path: \skin\res\drawable-hdpi\xx.png

Then the background image file path in the skin apk should also be: skin\res\drawable-hdpi\xx.png

(c) Methods of accessing resources

Copy Code code as follows:
Context context = Createpackagecontext ("Com.zj.skin", context.context_ignore_security);

Gets the context that corresponds to the Com.zj.skin, and can access any resource in the Com.zj.skin by the returned object.

For example: Apply apk to get the bg.png in the skin apk,

Copy Code code as follows:
drawable drawable = Context.getresources (). getdrawable (r.drawable.bg);

This allows you to get a reference to the picture, and other XML resource files are also captured in a similar way.

2 custom extension of the zip format of the skin

Focus: Read the resources in the zip file and the skin file storage strategy.

Scenario: If you read the skin file on the SD card every time you start, it will affect app execution speed. It is best to provide an interface for setting the skin, the user chooses the skin file to extract to the skin path, so do not need to read across the memory, faster, and do not need to go to the ZIP compression packet every time read, do not rely on the SD card files, even if the skin compression package has been deleted will not affect.

Implementation method:

(a) in the help of the software or the official website help prompts the user to copy the skin file to the SD card specified path.

b Provide a skin setting interface in the software. Can be in the menu or in the settings. can refer to ink, Sogou input method, QQ and other support for skin-changing software.

c) Load the skin file under the specified path, read the thumbnail, display in the Skin settings interface, and unzip the user's selected skin file to the skin path.

D The app first reads the resources under the skin path. If not, use the resources in APK.

I hope this article will help you with the Android program.

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.