Android for skin-changing function (i)

Source: Internet
Author: User

Last week, a friend gave advice to talk about the change of skin, it is a coincidence this week the company's work arrangements also have this demand, change the place of more and more, let a person to death. The so-called AX, first grind the knife, pull out a tool class, wrote a simple demo about skin changes.

There are several ways to implement skin skinning in Android, and I'm using a method that reads resources from another apk in a shared process space. As a general principle, let your app run in the same process as a resource-only app, so your app can access the resources of another app. The principle is very simple, the following steps we explain the implementation process.

One, the space that the shared process runs


By adding the same Android:shareduserid property value to the manifest root node under both projects, and by packaging the same signature file, the signature value of the two app is guaranteed, so the app can run in the same process. This is a prerequisite for resource file sharing.

Second, the abstract realization of resource sharing tool class

According to Reflectionutil's method area we can see that it has three functions: Getskincontext constructs a context instance based on the package name, Getidentifier is the corresponding resource ID based on the package name, resource folder name, resource name. The last color, drawable, and so on, returns a resource value that can be used directly, based on the package name and resource name.

Iii. Examples of Use

It's a bit cumbersome to use, and coding can be cumbersome when a lot of resources need to be replaced. Let's see the easy way.

Today's article is relatively short, if you have good ideas or other good implementation, please private messages to me, I will be in the following days after finishing to continue to introduce to you.

Source Address: Https://github.com/JackCho/SkinChangeDemo

If you find it helpful, you are welcome to subscribe to my public account-Android dry Sharing (Id:android_share). Below is the QR code, to provide you with timely high-quality Android dry.

?

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.