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.
?