1. Theme
A topic is a collection of formatted properties that contain one or more. Calling the topic resource in a program can change the style of the form, and has a global impact on the entire application or an activity.
Define location:res/values
In the file in the directory
Label
<style></style>: Define the topic
<item></item>: Set the style of the theme
Example (Define a theme called AppTheme)
<style name="AppTheme" parent=""> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style>
Use of the theme
(1) In the XML file: android:theme ="@style/AppTheme"
(2) In Java code: setTheme();
2. Style
Style: Set the specific style of the View.
Define location: in the file under the res/values directory
Label
<style></style>: Define style
<item></item>: Set the style of the control
Calling methods in XML files
style="@style/textViewSytle"
3. Custom style
When a custom style or theme cannot meet the needs, you can also customize the style. The steps to customize the style and theme are:
1) Create a style file in the res/values directory and add a<resources>
Root node.
2)<resources> Section
Add a <style> node to the point and define a unique name for the style or topic in the node. You can also choose to add a parent class attribute to indicate that the current style inherits the style of the parent class.
3) Declare one or more <item> in the <style> node. Each <item> node needs to define an attribute name and set the value of this attribute inside the element.
Summarize
(1) Style:
Styles and CSS styles in Android have similar functions. They are both used to define display styles for interface elements. They are a collection of one or more View control properties. Styles can only be used on a single View, such as EditText and TextView. Using styles, you can specify that the duplicate attributes of multiple controls have are extracted and written in a unified manner to avoid writing a large amount of duplicate code.
(2) Topic:
A theme is also a collection of one or more View control properties, but its scope of action is different. The topic is used in the <application> and <activity> nodes in the entire application or an activity, and its impact is global. If an application uses a theme and the view under the application also uses styles, then when the theme and the attributes in the style conflict, the style has a higher priority than the theme.
In the Android system, the styles and themes that come with them can be used directly, for example, you can set up the themes throughandroid:theme="android:style/…"。
This is the article about the use of theme styles in Android Studio. For more related android studio theme style content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!