While implementing the program functions, if you can make the program interface more beautiful, there is a icing on the cake.
First thought:
1) the skin, that is, the related resource files, are placed separately in a project, one skin and one engineering file. A project contains more than N resource files. The relationship between resources between multiple projects is that the file names and resource IDs are identical. different settings may be different for image resources and styles.
2) Configure Android: shareduserid = "com. Eric. skinmain" in androidmanifest. xml ".
Indicates that allow com. Eric. skinmain to access the resource file. com. Eric. skinmain in this project is the package name of the main project.
3) The main project uses this. createpackagecontext ("com. Eric. blackskin", context. context_ignore_security );
Obtain the context corresponding to com. Eric. blackskin, and then access any resources in COM. Eric. blackskin through the returned context object, just like accessing its own resources.
Note: Remember to first install the APK file corresponding to the skin Project
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;
}
}
});
}
}