Android skin replacement

Source: Internet
Author: User

Android skin replacement

Understand skin replacement implementation and differences between different solutions and usage scenarios.

I. functional division

1) The software has multiple built-in skins, which cannot be modified by the user;

2) The official website provides skin downloads. Users can use the downloaded skin;

3) The official website provides skin preparation tools or methods for users to make skin.

Ii. Skin Definition

The software skin includes icons, fonts, la S, interactive styles, etc. Skin replacement is to replace some or all of the skin's resources.

3. Separation of skin and app

1) Pack skin files

The default format is APK. For example, launcher, whose desktop skin format is an APK;

The custom format is zip. 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.

Iv. Resource Access

1) APK format

The condition for reading data between apks is that they have the same signature and androidmanifest. configure Android: shareduserid in XML to have the same attribute value, so that the two apks run in the same process and can access data from each other.

The method is as follows:

A) configuration in androidmanifest. xml of applications and skin programs

For example, Android: shareduserid = "com. ZJ"

B) the file name must be consistent with the skin file name of the same function in the application APK.

For example, the background image path of the application is \ skin \ res \ drawable-hdpi \ xx.png.

The path of the background image file in the skin APK should also be: Skin \ res \ drawable-hdpi \ xx.png

C) how to access resources

Context context = createpackagecontext ("com. ZJ. Skin", context. context_ignore_security );

Obtain the context corresponding to com. ZJ. skin, and access any resources in COM. ZJ. Skin 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

Focus: Read the resources in the ZIP file and the storage policy of the skin file.

Solution: If you read the skin files on the SD card at each startup, the app execution speed will be affected. It is best to provide a skin setting interface to decompress the selected skin file to the skin path, so that it does not need to be read across memory, which is faster, and does not need to be read from the zip package each time, it does not depend on the files in the SD card, even if the skin package is deleted.

Implementation Method:

A) Ask the user to copy the skin file to the path specified by the SD card with help from the software or official website.

B) 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.

C) 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 skin path.

D) The app preferentially reads Resources in the skin path. If not, use the resources in the APK.

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.