//先获取本地资源引用名称,type name是R.drawable.background中的"drawable",entry name是"background"
String resTypeName = getContext().getResources().getResourceTypeName(id);
String resEntryName = getContext().getResources().getResourceEntryName(id);
//然后创建皮肤包所在应用的Context
Context apk = getContext().createPackageContext(packageName,
Context.CONTEXT_IGNORE_SECURITY)
//然后就是获取皮肤包中的资源id了
int drawavleId = apk.getResources().getIdentifier(resEntryName, resTypeName,
apk.getPackageName());
private List<Integer> skinViewList = new ArrayList<Integer> (); private void scanViewGroup(ViewGroup group, List<Integer> skinViewList, Resources res) {
//first we need check if this ViewGroup have a background
if(group.getId() != View.NO_ID
&& res.getResourceEntryName(group.getId()).contains(SKIN_PATTERN)
&& !skinViewList.contains(group)) {
skinViewList.add(group.getId());
}
//second check its child view
View child;
for(int i = 0; i < group.getChildCount(); i++) {
child = group.getChildAt(i);
if(child instanceof ViewGroup) {
scanViewGroup((ViewGroup)child, skinViewList, res);
} else if(child.getId() == View.NO_ID) {
return;
} else {
int viewId = child.getId();
String entryName = res.getResourceEntryName(viewId);
Log("scanViewGroup(), entryName of this childView : " + entryName);
if(entryName.contains(SKIN_PATTERN) && !skinViewList.contains(child))
skinViewList.add(child.getId());
}
}
}
//先判断前面扫描的skinViewList是否为空,不为空意味着有控件需要换肤
if(skinViewList != null && skinViewList.size() > 0) {
int viewId = -1, backgroundId = -1;
for(int i = 0; i < attrs.getAttributeCount(); i++) {
if(attrs.getAttributeName(i).equals("id")) {
viewId = attrs.getAttributeResourceValue(i, -1);
}
if(attrs.getAttributeName(i).equals("background")) {
backgroundId = attrs.getAttributeResourceValue(i, -1);
}
}
//check if background drawable need save
if(viewId != -1 && backgroundId != -1 &&
drawableIdList != null && !drawableIdList.containsKey(viewId)) {
drawableIdList.put(viewId, backgroundId);
Log("add to drawableIdList, viewId = " + viewId
+ ", backgroundId = " + backgroundId);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有