1. Define the body color:
Three properties are customized in style:
They are not Android free properties, they are my custom properties. Their definition is written in attrs.xml.
Once defined here, it can be used directly in XML, just a reference to it.
eg. Android:background= "? ATTR/APPBG"
The background color is automatically converted to the attribute value you set.
2. Set Theme Colors
Activity provides a method setTheme (int id), but note that this is to be called before Setcontentview (int id). That means we're going to switch the color off before the view is displayed. This means that the current activity needs to be restarted.
In addition, previously rendered views need to be processed, which is to deal with "obsolete" activity. The way I use it here is to empty our back stack.
Final Intent themeintent = Getintent ();
Themeintent.setflags (Intent.flag_activity_new_task | Intent.flag_activity_clear_task);
StartActivity (themeintent);
Flag_activity_new_task is a new task stack for the ACTIVITY to start.
Flag_activity_clear_task any activity within the existing TASK that placed the activity is emptied. That is, emptying obsolete activity.
Graduation design experience and finishing-app-theme switch