In recent work, we need to implement the small wallpaper function and make the code into a demo.
The zip format is not used for skin replacement, because only an image background is replaced.
1. Put the three images into drawable-hdpi. I put the three images 480*800.
2. Use sharedpreference to access the skin ID, so that you can select the skin to use based on the ID at next startup, and refresh the skin in onresume ().
3. The data stored in sharedpreference uses string, and the image ID cannot be used, because the image ID is generated again after each program starts.
Let's just talk about the code.
Public class changeskinactivity extends activity {Private Static final string skin_id = "skin_id"; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); this. requestwindowfeature (window. feature_no_title); setcontentview (R. layout. main); button btnchangeskin = (button) findviewbyid (R. id. btnchangeskin); btnchangeskin. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {If ("bg0 ". equals (getskinresourcename () {setskinresourcename ("Bg1");} else if ("Bg1 ". equals (getskinresourcename () {setskinresourcename ("bg2");} else if ("bg2 ". equals (getskinresourcename () {setskinresourcename ("bg0") ;}refreshskin () ;}}) ;}@ override protected void onresume () {super. onresume (); refreshskin ();}/*** change skin * 1. click the shortcut menu for skin replacement * 2. after the program runs */private void refreshskin () {int skinid = getskinresourceid (); findviewbyid (R. id. layout ). setbackgroundresource (skinid);} private int getskinresourceid () {int skinid = R. drawable. bg0; string skinname = getskinresourcename (); If (skinname. equals ("Bg1") {skinid = R. drawable. bg1;} else if (skinname. equals ("bg2") {skinid = R. drawable. bg2;} return skinid;} private string getskinresourcename () {try {sharedpreferences preferences = getsharedpreferences ("skinxml", context. mode_private); Return preferences. getstring (skin_id, "bg0");} catch (exception e) {e. printstacktrace (); Return "bg0" ;}} private void setskinresourcename (string skinname) {sharedpreferences preferences = getsharedpreferences ("skinxml", context. mode_private); Editor editor = preferences. edit (); Editor. putstring (skin_id, skinname); Editor. commit ();}}
Then apply the results
: Http://download.csdn.net/detail/ethan_xue/4413167