Android _ How to switch themes or skins

Source: Internet
Author: User

Android _ How to switch themes or skins
1. Introduction

By using a custom topic or skin, you can place the related configurations (color, size, and so on) in a new apk compressed file. The directory structure remains consistent, the apk file can be placed in any accessible directory, like/system/framework/framework-res.apk, can dynamically load the theme file according to the needs of the software. Here we will only introduce this implementation method. If you are interested in other methods, you can study it on your own. It is mainly implemented by instantiating the AssetManager object and Resources object.

 

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


Related Article

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.