1.用自己的Layout实现layout监听
public class SkinActivity implements Layout{
SkinLayoutInflater skinLayoutInflator;
protected void onCreate(Bundle saveInstanceState){
skinLayoutInflator = new SkinLayoutInflater();
LayoutInflaterCompat.setFactory(getLayoutoutInflater().skinLayoutInflater);
}
public void update(){
SkinManager.loadPath("skin.apk");
SkinManager.update();
}
}
2.实现自己的LayoutInflaterFactory
public class SkinLayoutInflater implements LayoutInflaterFactory{
SkinLayoutInflater skinLayoutInflater;
private
public View createView(View parent,String name,String Context,AttributeSet attrs){
View view = null;
if(name.indexOf(".")!=-1)){//自定义控件
view = createView(context,attrs,name);
}else{//反射构造系统控件
for(String pre:prefixList){
view = createView(context,attrs,pre+name);
if(view == null){break;}
}
}
}
//反射View
public View createView(String name,String Context,AttributeSet attrs){
Class viewClazz = context.getClassLoader().loadClass(name);
Contructor<? extends view> contructor = viewClazz.getContructor(new Class[](Context.class,AttrubuteSet.class));
contructor.setAccessible(true);
}
//对从apk插件中得到的颜色进行应用
public void apply(){
for(SkinItem skinItem :list){
if("textColor".equals(skinItem.getAttrName())){
if(view instanceof TextView){
((TextView)view).setTextColor(skinItem.getId());
}else{
((TextView)view).setTextColor(SkinManager.getInstance().getColor(skinItem.getId()));
}
}
}
}
//skinitem的包装类
class SkinItem{
private String attrName;
private String attrValue;
String String attrType;
int id;
}
private void parseView(Context context,AttributeSet attrs,View view,String name){
for(int i=0;i<attrs.getAttributeCount();i++){
String attrName = attrs.getAttributeName(i);
String attrValue = attrs.getAttributeValue(i);
if("background".equal(attrName)||"textColor".equal(attrName)){
int id = Integer.parseInt(attrValue.substring(1));
String entryName = context.getResources().getResourceEntryName(id);
String typeName = context.getResources().getResourceTypeName(id);
SkinItem skinItem =new SkinItem(attrName,id,entryName,typeName);
list.add(skinItem);//收集换肤的ITem
}
}
if(!list.isEmpty){
SkinView skinview = new SkinView
}
}
class SkinManager{
private Context context;
private Resource skinResource;
private String skinPackageName;
private static SkinManager ourInstance = new SkinManager();
public SkinManager(){
}
public static SkinManager getInstance(){return ourInstance;}
public void init(Context context){
this.context = context.getApplicationContext();
}
//加载apk路径
public void loadSkin(File apkPath){
PackageManager packageManager = coontext.getPackageManager();
PackageInfo packageInfo = packageManager.getPackagerArchiveInfo(apkPath.getAbsolutePath,PackageManager.GET_ACTIVITIE);//这里很重要,根据packageManage来加载apk包信息和包资源
skinPackageName = packageInfo.packageName;
AssetManager assetManager = AssetManager.class.newInstance();
Method addAssetPath()=assetManager.getClass.getClass.getMethod("addAssetPath",String.class);
addAssetPath.invoke(assetManager.apkPath.getAbsoluteFile());
skinResource = new Resource(assetManager,context.getResources().getDisplayMetries,context.getResources().getContext);
}
//对每个View进行更新
public void update(){
for(View view : cacheMap.keySet()){
SkinView skinitem = cacheMap.get(view);
skinItem.apply();
}
}
public int getColor(int resId){
if(skinResource == null){
return resId;
}
String resName = context.getResources().getResoucesEntryName(resId);//得到资源名
int skinId = skinResource.getIndentifier(resName,"color",skinPackageName);//通过资源名去拿到皮肤ID
return skinResource.getColors(resId);
}
}
class SkinView{
private View view;
private List<SkinItem> list;
public SkinView(View view,List<SkinItem> list>) {
this.view = view;
this.list = list;
}
//将ViewItem里面需要换肤的进行更新
public void apply(){
for(SkinItem skinItem :list){
if("textColor".equals(skinItem.getAttrName())){
if(view instanceof TextView){
(TextView)view .setTextColor(skinItem.getId());
}else if(view instanceof Button){
(TextView)viwe.setTextColor(skinItem.getId);
}
}
}
}
}
}
相关推荐
简单通过修改R.mipmap.test文件,实现app换肤功能,简单实现原理讲解
此Demo中主要是仿QQ换肤功能的实现,希望用到的朋友尽情下载
该资源是 Android 应用实现换肤功能的demo程序,同时也是博客文章:http://blog.csdn.net/janice0529/article/details/39999727 中demo程序, 博客中有详细的demo程序设计介绍。
pc或者移动端实现换肤功能还是比较简单的,大致就是需要换肤的css,还有正常的css;把当前皮肤类型存入本地;然后通过js读取并判断当前应该加载哪套css。 由于微信小程序没有操作wxss的api,所以实现的方式有点不...
1、资料包括安卓app源代码和产品设计说明相关文档,有助于理解整个app设计开发过程。 2、资源内容:安卓app框架源代码文档 3、使用/学习目标:了解移动开发核心原理 4、应用场景:安卓编程,项目产品化、资源处理等内容...
主要介绍了Android App中内置换肤功能的实现方式,文中举了一个类似QQ空间中换肤方式的例子作为说明,需要的朋友可以参考下
在很多软件中拥有换肤功能,包括边框图片切换,颜色切换,字体颜色、样式、大小等,其中尤为常见的就是小说软件的背景色切换。实现一个用于改变文字颜色的上下文菜单。
换肤功能是在APP开发过程中遇到的比较多的场景,为了提供更好的用户体验,许多APP会为用户提供切换主题的功能。主题颜色管理涉及到的的步骤有 颜色配置 使用颜色 UI元素动态变更的能力 动态修改配置 主题包管理...
pc或者移动端实现换肤功能还是比较简单的,大致就是需要换肤的css,还有正常的css;把当前皮肤类型存入本地;然后通过js读取并判断当前应该加载哪套css。 由于微信小程序没有操作wxss的api,所以实现的方式有点不...
媒体秀APP是一款基于android平台,可以实现多种媒体娱乐功能的多功能媒体娱乐APP。 主要功能如下: 1. 手机本地音乐播放。支持四种播放模式,支持后台播放,新增“我喜爱的”列表用于管理用户喜爱的歌曲。 2. 手机...
试着用鸿洋大神写的SkinManager实现了换肤功能。 一、配置 在app下build.gradle中添加依赖: //换肤功能 compile 'com.zhy:changeskin:4.0.2' 这样就配置好了,然后在程序入口进行初始化。 二、全局初始化 在自己...
视频播放功能直播功能弹幕功能换肤功能… 本系列文章,将会有记录以上功能的实现但不仅仅只有这些,还会有一些其他,比如自定义控件、利用fiddler抓包等,接下来就进入本篇的主题——《仿bilibili刷新按钮的实现》。
在Android中实现界面切换的例子,一共有2个Android换肤实例,都是挺简单的,只演示了基本的换肤原理,都生成有APK文件,可拷贝到android手机运行看效果,在些不多做介绍了,Android换肤相信是个实用的功能。
以Bloc方式实现状态管理,一键换肤等功能。实现了屏幕适配,可自定义分区正在加载的请求封装,分离开发,测试,生产环境,WebView自然也一定要有咯。项目大部分都使用Flutter本机API来完成。使用少量原生插件。喜欢...
2、准备工作做好了,开始换肤 2.1新建一个文件夹styles,在里面新建一个文件theme.less 定义一个.theme()方法,写上需要的颜色参数如图: 2.2 styles文件夹下再新建一个存放各类主题的color.less文件,里面根据自己...
本文分析了Android实现换肤的两种思路。分享给大家供大家参考,具体如下: 这里来了解换肤实现及不同方案的差异和使用场合。 一、从功能上划分 1) 软件内置多个皮肤,用户不能修改; 2) 官方提供皮肤下载,用户使用...
3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 -------- -----------------------------...
源码能够动态更改导航条和字体颜色,用于实现app换肤功能,模仿QQ的换肤,实现方式很初级.仅供参考学习,喜欢的朋友可以下载学习一下,源码天堂IOS源码频道免费提供下载。