Skin replacement for Android (2)
The last chapter I wrote two days ago has received a good response on the skin replacement function. Today I will introduce you to another method. Today's implementation strategy was also suggested by netizens. Then I wrote a demo myself to evaluate the advantages and disadvantages of the first method.
This section briefly introduces some unfriendly aspects of the first method for skin replacement. For example, if you click the skin replacement function key, you need to download a resource apk and then reference the resource ID, it is indeed inconvenient for users to use. The method we introduced today is to overcome this drawback, which enables direct switching within the application and storing resource files in the local apk, making it easier to read and operate, the following describes an implementation logic.
There are several features to achieve skin replacement: one is to replace image resources, and the other is to change the text color, size, and content. The implementation policy is implemented based on the asserts directory. If there are two sets of skins that can be changed, we need to create two directories corresponding to the two skins under the asserts folder, they have resources with the same name (including image resources and properties files ). If the first skin is used, all resources in the first directory are called. If the second skin is called, resources in the other directory are used. Because the resources referenced in asserts do not need to be the same as res resources, but can be implemented by calling the corresponding resource path through AssertManager, it is a little less troublesome to implement the R file. Changes in text color and other attributes are stored in properties. You only need to call the attribute values in Properties, which is very simple and convenient. The following is a simple example.
I. References to image resources
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Export/cG91ta3vcq9yKXKtc/Wo6zSu8rHQml0bWFwo6y2/srhrhjhd2fiber gwho9xiwo/export + export = "http://www.2cto.com/uploadfile/Collfiles/20140811/2014081110193762.jpg" alt = "\">
Before loading the TextView property value, remember to initialize Properties first. All the property values are in properties.
Iii. Use
Click the button to switch the skin content.
Today's article is short. If you have good ideas or other skin-changing implementations, please trust me and I will continue to introduce it to you in the next few days.
Source Code address: https://github.com/JackCho/SkinChangeDemo2
If it is helpful to you, you are welcome to subscribe to my public account --Android sharing (ID: android_share). The QR code below provides you with timely and high quality Android dry goods.