Android_ How to switch themes or skins

Source: Internet
Author: User

1. Introduction

Using a custom theme or skin, you can put the relevant configuration (color, size, etc.) in a new apk compression file, the directory structure is consistent, the APK file is placed in any directory can be accessed, similar to/system/framework/ framework-res.apk, the theme files can be dynamically loaded according to the needs of the software. This is the only way to achieve this, and other ways of interest can be studied by themselves.

The main instantiation of the Assetmanager object and the resources object to implement the

Assetmanager Assetmanager = AssetManager.class.newInstance (); Method Addassetpath = Assetmanager.getclass (). GetMethod ("Addassetpath", String.class); Addassetpath.invoke ( Assetmanager, Skinpkgpath); Resources superres = Context.getresources (); Resources Skinresource = new resources (Assetmanager,superres.getdisplaymetrics (), superres.getconfiguration ());

2. Flowchart




3. Notes

There is a good open source project on GitHub Https://github.com/fengjundev/Android-Skin-Loader, interested friends can study the source code

Copyright NOTICE: This article is a sub-ink original article, not allowed to reprint without Bo master.

Android_ How to switch themes or skins

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.