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