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.