android类似QQ换皮肤,实现思路,apk资源共享
	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的按钮设置监听。
	Java代码 
	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);   
	
相关新闻>>
- 发表评论
 - 
				
 
- 最新评论 进入详细评论页>>
 





