Android for skin-changing function (ii)

Source: Internet
Author: User

The first two days of writing Oberzhang about the function of skin change has been very good response, today for everyone to introduce another way. Today's implementation of the strategy is also suggested by netizens, and then I wrote a demo, we evaluate the first way compared to the advantages and disadvantages of where.

A brief introduction of the first on the implementation of the method of skin-changing some unfriendly places, such as click on the function of the skin change, you need to download a resource apk, and then to refer to the resource ID, there is a lot of inconvenience to users. Today for everyone to introduce the method is to overcome this disadvantage, can be achieved directly in the application of the switch, the resource files stored in the local APK, read and operate is more convenient, the following describes a general implementation of the logic.

The general realization of the function of skin-changing there are a few things: one is the replacement of the picture resources, the second is the text color, size, text content changes. The implementation of the strategy is based on the asserts directory to achieve, assuming that there are two sets of skin can be replaced, we need to create a new two sets of skins under the asserts folder directory, and they have the same name of the resources (including picture resources and properties files). With the first set of skins, all the resources in the first directory are called, and the second set of skins is invoked using resources from another directory. Because referencing asserts resources do not need to be like res resources, but need to call the corresponding resource path through Assertmanager can be implemented, so the implementation of the R file will be a little cumbersome. The changes in the properties of the text color and so on are uniformly preserved in the properties, it is necessary to call the property values on the call can be, very simple and convenient. The following is a demonstration of the simple use.

I. References to picture resources


General loading pictures will be implemented in two ways, one is bitmap, the other is drawable. Here too, there are ways to implement it.

Second, about the TextView property value loading

Before loading the TextView property value, be sure to initialize the properties first, all of the property values are in the attributes.

Third, the use

Click the button to toggle skin content.

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/SkinChangeDemo2

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.