NetEase News has a small function, although the function is small, but look out of the big company's product design is indeed very good, today to implement the next function, if the user click on the choice of night mode or daytime mode, then all the activity background to change, in fact, Android source to each activity The content area defines an ID, which is Android. R.id.content, because all the activity background to change color, therefore must write a base class, the code is as follows:
public class Baseactivity extends Activity { protected void onCreate (Android.os.Bundle savedinstancestate) { Super.oncreate (savedinstancestate); }; @Overridepublic void Setcontentview (int layoutresid) {Super.setcontentview (layoutresid);(((viewgroup) Findviewbyid ( Android. r.id.content). Getchildat (0)). SetBackgroundColor (Getresources (). GetColor (true? R.color.root_view_background_color_night:r.color.root_view_background_color));}}
The user clicks the daytime or the night mode, certainly is to store a value to the sharedpreferences, I in above the code is writes true, if the real project certainly is reads from the sharedpreferences file, is this, simple!
Android High Imitation NetEase news night mode