Graduation design experience and finishing-app-theme switch

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.