Haven't written a blog for a long time, looking at more than two articles per month more than three of the rhythm, feel that they have not been saved ~ plan to two articles each week, the pressure is big said. Ya minute fly butterfly
For a new company .
Now in the app is simply thriller, is a NetEase + Weibo + Baidu map + enhanced version, one months can make a demo, I really give the present colleague next kneeling and not reliable party a Orz
To get to the point, now in the app needs to achieve the effect of click to change skin, similar to NetEase cloud music of red and black skin switching effect (of course, here is simplified, the current in the app only the title bar and sidebar skin color needs to switch, and the night day mode switch is not the same, that complex). First of all, the idea can be implemented with Android Sharedpreferences, set the default red skin storage 0, set the black skin storage 1.
The following begins the code:
I have written a tool class that can be used to determine the current skin pattern and to implement a toggle
//Tool class public class skinmode{private context context; Private Sharedpreferences Skinmode; Public Skinmode (Context context) {Skinmode = Context.getsharedpreferences (); }//Get skin mode, 0 for default red, 1 for black public int getskinmode () {return Skinmode.getsharedpreferenc ES ("Skinmode", 0); }//Set skin mode public void Setskinmode (int skinmode) {skinmode.put ("Skinmode", Skinmode); public void Setviewskinmode (View view,int skinmode) {if (0==skinmode) {Setskinmode (Skinmode); mode switch View.setbackgroundcolor (color.red);//Set Color} else if (1==skinmode) {Setskinmode (Skinmode); View.setbackgroundcolor (Corlor.black); } }}
Day and night mode switch is also involved in Font transformation, control transparency and so on, more complex, this I can not do ~
Another problem is that when you click on the GridView item, it's easier to implement a checkbox-like radio effect.
The code is implemented as follows:
gridview.setOnItemClickListener(new OnItemClickListener( AdapterView view,View view,int position,long id){ for(int i=0;i<gridview.getChildCount();i++) { TextView tv = (TextView)gridview.getChildAt(i); tv.setBackroundColor(color.Black); // 默认是黑色 } view.setBackgroundColor(color.Red);//点击后是红色}
)
Thats all
App skinning ideas and ListView item click