博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 给应用定制皮肤
阅读量:5815 次
发布时间:2019-06-18

本文共 3028 字,大约阅读时间需要 10 分钟。

hot3.png

在实现程序功能的同时,如果能让程序界面更加美观,有锦上添花之妙.

先说思路:
1)皮肤也就是相关的资源文件单独放置在某个工程中,一种皮肤一个工程文件.一个工程包括N多的资源文件,多个工程间资源的关系是,文件名,资源ID等完全一样.不同的可能是图片资源,style等的设置不一样.
2)皮肤工程在AndroidManifest.xml中配置android:sharedUserId="com.eric.skinmain".
     表明允许com.eric.skinmain访问本工程中的资源文件. com.eric.skinmain是主项目的包名
3)主项目通过 this.createPackageContext("com.eric.blackskin",Context.CONTEXT_IGNORE_SECURITY);
获取到com.eric.blackskin对应的Context,然后通过返回的context对象就可以访问到com.eric.blackskin中的任何资源,如同访问自身的资源一样.
\

\

public class main extends Activity {	        /** Called when the activity is first created. */	        private LinearLayout showBg;	        private Button btn;	        private Context green_skin_Context = null;	        private Context black_skin_Context = null;	        int flag = 0;	        @Override	        public void onCreate(Bundle savedInstanceState) {	                super.onCreate(savedInstanceState);	                setContentView(R.layout.main);	                showBg = (LinearLayout) findViewById(R.id.linear_layout_1);	                try {	                        green_skin_Context = this.createPackageContext(	                                        "com.eric.greenskin", Context.CONTEXT_IGNORE_SECURITY);	                } catch (NameNotFoundException e) {	                        e.printStackTrace();	                }	                try {	                        black_skin_Context = this.createPackageContext(	                                        "com.eric.blackskin", Context.CONTEXT_IGNORE_SECURITY);	                } catch (NameNotFoundException e) {	                        e.printStackTrace();	                }	                btn = (Button) findViewById(R.id.btn_change_skin);	                btn.setOnClickListener(new OnClickListener() {	                        @Override	                        public void onClick(View v) {	                                if (flag == 0) {	                                        showBg.setBackgroundDrawable(green_skin_Context	                                                        .getResources().getDrawable(R.drawable.bg));	                                        btn.setBackgroundDrawable(green_skin_Context	                                                        .getResources().getDrawable(R.drawable.btn_normal));	                                       	                                        flag = 1;	                                } else if (flag == 1) {	                                        showBg.setBackgroundDrawable(black_skin_Context	                                                        .getResources().getDrawable(R.drawable.bg));	                                        btn.setBackgroundDrawable(black_skin_Context	                                                        .getResources().getDrawable(R.drawable.btn_normal));	                                        flag = 0;	                                }	                        }	                });	        }	}

 

转载:http://www.adobex.com/android/source/details/00000423.htm

转载于:https://my.oschina.net/androidcode/blog/105093

你可能感兴趣的文章
TEST
查看>>
PAT A1037
查看>>
(六)Oracle学习笔记—— 约束
查看>>
[Oracle]如何在Oracle中设置Event
查看>>
top.location.href和localtion.href有什么不同
查看>>
02-创建hibernate工程
查看>>
svn命令在linux下的使用
查看>>
Gradle之module间依赖版本同步
查看>>
java springcloud版b2b2c社交电商spring cloud分布式微服务(十五)Springboot整合RabbitMQ...
查看>>
10g手动创建数据库
查看>>
Windwos Server 2008 R2 DHCP服务
查看>>
UVa 11292 勇者斗恶龙(The Dragon of Loowater)
查看>>
d3 v4实现饼状图,折线标注
查看>>
微软的云策略
查看>>
Valid Parentheses
查看>>
性能测试之稳定性测试
查看>>
ES6的 Iterator 遍历器
查看>>
2019届高二(下)半期考试题(文科)
查看>>
nginx 301跳转到带www域名方法rewrite(转)
查看>>
AIX 配置vncserver
查看>>