Android换肤
来源:互联网 发布:吗288清零软件 编辑:程序博客网 时间:2024/05/17 06:30
换肤有多种方案,但用到的最终方法都是一样的,就是用新的Resource读取apk里的资源
/**
* 生成皮肤包的AssetManager
*
*@paramapkPath
*@return
*/
privatestaticAssetManager createAssetManager(String apkPath) {
try{
AssetManager assetManager = AssetManager.class.newInstance();
try{
AssetManager.class.getDeclaredMethod("addAssetPath",
String.class).invoke(assetManager, apkPath);
}catch(Throwable th) {
th.printStackTrace();
}
returnassetManager;
}catch(Throwable th) {
th.printStackTrace();
}
returnnull;
}
/**
* 获取Bundle中的资源
*@paramcontext
*@paramapkPath
*@return
*/
publicstaticResources getBundleResource(Context context, String apkPath){
AssetManager assetManager =createAssetManager(apkPath);
returnnewResources(assetManager, context.getResources().getDisplayMetrics(), context.getResources().getConfiguration());
}
在如何使用新的Resource时,就有多种方案,比如反射context里的resource,直接把设置为新的,但这种要注意到apk的更新,另外一种,是自己弄个资源管理器,每次都从资源管理器里读取资源,不使用R
如调用string类型的名为name的字符串,defPackage为apk路径
/**
* Return a resource identifier for the given resource name. A fully
* qualified resource name is of the form "package:type/entry". The first
* two components (package and type) are optional if defType and
* defPackage, respectively, are specified here.
*
* <p>Note: use of this function is discouraged. It is much more
* efficient to retrieve resources by identifier than by name.
*
* @param name The name of the desired resource.
* @param defType Optional default resource type to find, if "type/" is
* not included in the name. Can be null to require an
* explicit type.
* @param defPackage Optional default package to find, if "package:" is
* not included in the name. Can be null to require an
* explicit package.
*
* @return int The associated resource identifier. Returns 0 if no such
* resource was found. (0 is not a valid resource ID.)
*/
public int getIdentifier(String name, String defType, String defPackage) {
if (name == null) {
throw new NullPointerException("name is null");
}
try {
return Integer.parseInt(name);
} catch (Exception e) {
// Ignore
}
return mAssets.getResourceIdentifier(name, defType, defPackage);
}
* Return a resource identifier for the given resource name. A fully
* qualified resource name is of the form "package:type/entry". The first
* two components (package and type) are optional if defType and
* defPackage, respectively, are specified here.
*
* <p>Note: use of this function is discouraged. It is much more
* efficient to retrieve resources by identifier than by name.
*
* @param name The name of the desired resource.
* @param defType Optional default resource type to find, if "type/" is
* not included in the name. Can be null to require an
* explicit type.
* @param defPackage Optional default package to find, if "package:" is
* not included in the name. Can be null to require an
* explicit package.
*
* @return int The associated resource identifier. Returns 0 if no such
* resource was found. (0 is not a valid resource ID.)
*/
public int getIdentifier(String name, String defType, String defPackage) {
if (name == null) {
throw new NullPointerException("name is null");
}
try {
return Integer.parseInt(name);
} catch (Exception e) {
// Ignore
}
return mAssets.getResourceIdentifier(name, defType, defPackage);
}
0 0
- Android应用换肤
- android 换肤
- android 换肤
- Android换肤apk
- android 换肤 .
- Android应用换肤
- android换肤
- android换肤
- android换肤机制
- Android应用换肤
- android换肤实现
- Android换肤技术
- Android换肤Demo
- Android换肤系列
- Android换肤
- Android换肤框架
- android动态换肤
- Android 换肤小结
- Android中使用广播机制退出多个Activity
- 一道笔试题:假设在n进制下,下面的等式成立,n的值是(),567*456=150216.
- Angular Material vs. Material Design Lite
- Solr配置,schema.xml的配置,以及中文分词
- 列式数据库与行式数据库
- Android换肤
- HDFS High Availability体系介绍(Using the Quorum Journal Manager)
- 【linux开发】IO端口和IO内存的区别及分别使用的函数接口
- 阳光总在风雨后
- log4j
- VMware vSphere服务器虚拟化实验五 vCenter Server 网络管理
- S06 E04 GOT
- Android的WebView退出后flash视频播放器无法退出的问题:
- android 中webview退出当前页面仍然继续播放的问题