Good post:
Android viewflipper for left and right sliding Animation
Http://www.eoeandroid.com/thread-235446-1-1.html
Android Treeview Tree Structure
Http://www.eoeandroid.com/thread-235033-1-1.html
Some time ago, I studied launcher and made a desktop that can switch skin like a dim sum desktop. So I will share with you the IMPLEMENTATION OF THE APPLICATION skin. In this way, the main application is an APK, the skin is an APK, and the installed APK is read in the main application.
Attach several cut charts first
Here is the androidmanifest. xml of the skin APK.
package = "com. app. greenskinexample "
Android: versioncode =" 1 "
Android: versionname = "1.0">
Android: Label =" @ string/app_name ">
<Action Android: Name = "com. App. skinexample. Theme"/> is important. We can find this skin in the main application. Then, put the required image, text, and color Resources in the res folder of the APK.
In the main application APK, we use the followingCodeSegment to read the skin APK
Public Static FinalString theme_action = "com. App. skinexample. Theme";PublicList <resolveinfo>Themes;Public VoidGetallthemes () {intent mintent=NewIntent (theme_action); packagemanager pm=Getpackagemanager (); themes= PM. queryintentactivities (mintent, 0);}
The most important thing is how to replace the original one with the skin APK in the main APK. Let's take a look at the code.
Public Resources themeresources = Null ; Public String themepackage; Public Void Themeloading () {packagemanager pm = Getpackagemanager (); Try {Themeresources = PM. getresourcesforapplication (themepackage );} Catch (Namenotfoundexception e ){ // The saved theme was uninstalled so we save the default one } Drawable icon = Null ; Int Resource_id = themeresources. getidentifier (resourcename, "drawable" , Themepackage ); If (Resource_id! = 0 ) {Icon =Themeresources. getdrawable (resource_id );}}
Desktop skin Implementation MethodProgramSource code:
Themeutil. Java
Public Static Void Displaytoast (context, string text) {Toast toast; toast = Toast. maketext (context, text, Toast. length_short); toast. setgravity (gravity. Center, 0, 0 ); Toast. Show ();} Public Static Void Loadthemeresource (Resources themeresources, string themepackage, string item_name, view item, Int Themetype) {drawable d = Null ; If (Themeresources! = Null ){ Int Resource_id = themeresources. getidentifier (item_name, "drawable" , Themepackage ); If (Resource_id! = 0) {D = Themeresources. getdrawable (resource_id ); If (Themetype = themeattributes. theme_item_foreground & item Instanceof Imageview) {drawable TMP = (Imageview) item). getdrawable (); If (TMP! = Null ) {TMP. setcallback ( Null ); TMP =Null ;} (Imageview) item). setimagedrawable (d );} Else {Drawable TMP = Item. getbackground (); If (TMP! = Null ) {TMP. setcallback ( Null ); TMP = Null ;} Item. setbackgrounddrawable (d );}}}} Public Static Drawable loadthemedrawable (Resources themeresources, string resourcename, string themepackage) {drawable icon = Null ; Int Resource_id = themeresources. getidentifier (resourcename, "drawable" , Themepackage ); If (Resource_id! = 0 ) {Icon = Themeresources. getdrawable (resource_id );} Return Icon ;} Public Static Int Loadthemecolor (Resources themeresources, string resourcename, string themepackage ){ Int Color = 0 ; Int Resource_id = themeresources. getidentifier (resourcename, "color" , Themepackage ); If (Resource_id! = 0 ) {Color = Themeresources. getcolor (resource_id );} Return Color ;}
Starting address: http://www.eoeandroid.com/thread-231199-1-1.html
Download the source code: launcherskinexample.zip