Analysis of two ways of thinking of Android to realize skin peeling

  • 2020-11-20 06:14:13
  • OfStack

This paper analyzes two ways of thinking of Android skin peeling. To share for your reference, the details are as follows:

Here to understand the implementation of the skin and different solutions and use of the differences.

1. Functional division

1) Multiple skins are built into the software, which cannot be modified by users;

2) Official skin download is provided, and users use the downloaded skin;

3) The authorities provide tools or methods for making skin. Users can make their own skin.

2. Definition of skin

Software skin includes ICONS, fonts, layout, interactive style, etc., and skin is to replace some or all of the resources included in the skin.

3. Skin is separated from APP

1) Package skin files

The default format is apk. Launcher, for example, has a desktop skin format of 1 apk;

The custom format is zip. For example, the ink weather skin extension is mja, and the sogou input skin extension is sga, and their file format is actually zip.

4. Resource access

1) apk format

The condition for reading data between apk is that they have the same signature and that android:sharedUserId is configured in ES40en.xml to have the same attribute value, so that two apk running in the same process can access each other's data.

The methods are as follows:

a) configuration in ES50en.ES51en for applications and skinning programs

Such as:

android:sharedUserId="com.zj"

b) file and apk application for the same function of the skin file name to 1

For example: Background image path for the application: \Skin\res\ drawable-ES64en \ XX.png

The background image file path in the skin apk should also be: Skin\res\ drawable-ES73en \ XX.png

c) methods of accessing resources

Context context = createPackageContext("com.zj.skin", Context.CONTEXT_IGNORE_SECURITY);

Get the corresponding Context to com.zj.skin, and you can access any resource in ES88en.zj.skin by returning the context object.

For example, to apply apk to obtain bg. png in apk,

Drawable drawable = context.getResources().getDrawable(R.drawable.bg);

This gives you a reference to the image, and other xml resource files are obtained in a similar way.

2) Custom extensions for zip format skins

Important: Read the resources in the zip file and the skin file storage policy.

Scenario: If the skin file on the SD card is read at each startup, the APP execution speed will be affected. It is better to provide the interface to set the skin and uncompress the skin files selected by the user into the skin path, which does not need to read across memory, is faster, and does not need to read every time in the zip compressed package, and does not depend on the files in the SD card, even if the skin compressed package is deleted.

Implementation method:

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

b) provides a skin setting interface in the software. It can be in the menu or in Settings. You can refer to ink, sogou input method, QQ and other software to support skin peeling.

c) to load the skin file under the specified path, read the thumbnails therein, display them in the skin Settings interface, and extract the selected skin file under the skin path.

d) APP gives priority to read resources under the skin path. If not, use the resources in apk.

I hope this article has been helpful for Android programming.


Related articles: