android 类似QQ 换皮肤 实现思路 apk资源共享
android 类似QQ 换皮肤 实现思路 apk资源共享
发布:t80t90s | 发布时间: 2013年3月30日
1、首先在AndroidManifest.xml中的<manifest>中加入android:sharedUserId="共享id"----具有相同id的apk可以不受限制访问。
2、根据包名创建Context,在Activity下有提供方法createPackageContext能够依据包名创建。
3、获取共享的Apk资源。
注意:
1、Activity中的findViewById()与View中的findViewById()区别在于:
Activity需要对setContextView()后的Layout才能由findViewById()获得View。
View只需要有对象即可由findViewById()获得在View中包含id的View。
2、在资源获取方面主要获取那个apk下的资源主要是由Context决定。
在资源apk没安装前:
资源文件安装后:
主apk包名:com.app.share;
资源apk包名:com.app.share2;
主Activity中获取资源apk中R,并且生成Layout对id为button1的按钮设置监听。
public class StartAct extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
Button btn = new Button(this);
btn.setText("TO SECOND");
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(StartAct.this, SecontAct.class);
StartAct.this.startActivity(intent);
}
});
this.setContentView(btn);
try {
Context other = this.createPackageContext("com.app.share2", CONTEXT_IGNORE_SECURITY|CONTEXT_INCLUDE_CODE);
Class<?> c = other.getClassLoader().loadClass("com.app.share2.R");
Class<?>[] cl = c.getClasses();
int b =0;
for (int i = 0; i < cl.length; i++) {
Log.d("TAG", cl[i].getSimpleName());
Field field[] = cl[i].getFields();
for (int j = 0; j < field.length; j++) {
Log.d("TAG", "NAME:"+field[j].getName()+"--VALUE:"+field[j].getInt(field[j].getName()));
if(field[j].getName().equals("button1")) {
b = field[j].getInt(field[j].getName());
Log.d("TAG", "--------id");
}
};
}
View v = LayoutInflater.from(other).inflate(R.layout.main, null);
Button btn1 = (Button) v.findViewById(b);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("TAG", "BUTTON FROM Share2");
Toast.makeText(StartAct.this, "BUTTON FROM Share2", Toast.LENGTH_SHORT).show();
}
});
this.setContentView(v);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
资源apk包Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Share2"
/>
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
android 类似QQ 换皮肤 实现思路 apk资源共享相关推荐
- Android实现QQ换头像的对话框
之前一直觉得QQ换头像弹出的对话框挺好看的,而且在项目中也有这个 需求,于是写一个Demo出来分享一下. 话不多说,先来张效果图看看. 上面是QQ中的效果. 上面的效果图为需要实现的效果. 简单来说, ...
- android类似QQ空间,微信朋友圈,微博主页源码
2019独角兽企业重金招聘Python工程师标准>>> 类似QQ空间,微信朋友圈,微博主页等,展示图片的九宫格控件,自动根据图片的数量确定图片大小和控件大小,使用Adapter模式设 ...
- android 仿qq换肤功能,Android插件化的思考——仿QQ一键换肤,思考比实现更重要!.doc...
Android插件化的思考--仿QQ一键换肤,思考比实现更重要! 关于QQ的换肤,他们的实现思路我不是很清楚,但是你可以看一下这张换肤的截图 我们想使用哪个主题就直接下载就好了,这一实现的过程我们大致 ...
- Android类似QQ弹窗效果
QQ的消息提醒有通知栏的还有弹出对话框的,怎么样才能有这种效果: 我是这样做的,不知道对不对,希望大家互相学习. 1.布局文件照着他这样做,代码: <?xml version="1.0 ...
- 关于Android类似qq和微信那种在桌面图标右上角更新数字的研究
记录下这个需求的研究 写的超级随意 大家凑合看 不懂再问 一起探讨 因为我们的产品也需要有即时通讯了 消息更新不可避免 首先 要实现这个功能 当然是要借助系统的Launcher. 而谷歌并 ...
- android 类似qq空间微博微信九宫格图片
直接给代码吧: import android.content.Context; import android.content.res.TypedArray; import android.graphi ...
- qq游戏大厅+android,android 类似qq游戏大厅这种启动问题
问题:进入程序后A,A又进入程序B(其实A,B就是两个不同的apk,已安装好的),在B中自由操作到任何Activity.操作过程中按了home键返回主界面后,再启动时候要求从A的初始化界面进去(即从启 ...
- Android仿QQ侧滑菜单
先上效果图: GIF图有点模糊,源码已上传Github:Android仿QQ侧滑菜单 ####整体思路: 自定义ItemView的根布局(SwipeMenuLayout extends LinearL ...
- 图片HSL颜色调节(仿QQ换肤)
下载了vs2010,今天终于可以初步体验了.看好的高级调试功能IntelliTrace功能没能符合我的预期,居然不支持局部变量,这样这个功能似乎就显得鸡肋了.随便写点什么体验下,就决定实现了这个类似Q ...
最新文章
- CISSP的成长之路(二):为什么要获得CISSP认证
- 从容稳进,高通正扎实推进5G
- Java中的门面设计模式,非常有用!
- c语言二维图形变换程序,【计算机图形学】3-2 二维几何变换根本代码
- SQL Server 2005的安装,SQL Server 2005系列之一
- autojs调用java识字_autojs实现抽象类的继承
- 收藏 | 深度学习调参有哪些技巧?
- 利用PHP安装windows自动运行的服务,PHP程序可以实现长时间、自动运行、定时更新功能,直接可以用在项目中的类源代码...
- 帮助中心 开源_如何不获得开源帮助
- 上万规模数据湖如何在实验室测试
- JS对象拷贝:深拷贝和浅拷贝
- 哈工大c语言作业系统,2015秋C语言程序设计
- python ** 运算符_Python入门(9)运算符 — 位运算符、成员运算符、身份运算符...
- appinventor贪吃蛇制作步骤_旋转RGB制作指导
- Matlab编程与C编程的不同
- Python内置函数(7)——sum
- “一路有你”——迷你TXT小说阅读器 V2.8 正式版 发布!
- Servlet实现登录带有验证码验证案例
- 关于MSXML3.dll与MSXML6.dll
- ISO光盘镜像导入到U盘的方法