Android theme Application

Source: Internet
Author: User

Android theme Application

Enter the text directly!

To set a topic, you must first define a custom attribute value,

Attrs. xml

 

     
                      
  
 

Then, define the corresponding style.

 

Styles. xml

 

    
OK. You can use it now!

 

Main. xml

 
Of course, you also need to set it in the onCreate method of Activity when actually using it:

 

 

setTheme(R.style.Bule);
// Note that you must set the topic setContentView (R. layout. activity_main) before setContentView );
The setting is complete. Let's see the results ~

 

Now there is a problem: when we have two or more topics, if you want to obtain a value of the current topic (for example, to obtain the textColor value of the current id: TV _test ), what should we do?

Very simple. Two sentences of code:

 

TypedArray ta = getTheme().obtainStyledAttributes(R.styleable.my_styleable);
// Note: The R. styleable. my_styleable_colorValue is actually automatically generated int color = ta. getColor (R. styleable. my_styleable_colorValue, 0 );
// By the way, do not forget to add the following sentence
ta.recycle();

OK.

 

 

 

Related Article

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.