First, let's explore what the style is.
There is a scenario where, when we write a layout file, there are many views, they have the same properties, and if each view is written again with the same attributes, it would seem like a cumbersome code.
And in the maintenance of the code is very inconvenient, then we can be the same properties of the code extracted, put into the styles.xml, so that we modify the code.
How do I declare a style?
Create a <style> node in the Styles.xml file, and then add the <item> child nodes to this node, such as:
<stylename= "Button_pre_style"> <Itemname= "Android:layout_width">Wrap_content</Item> <Itemname= "Android:layout_height">Wrap_content</Item> <Itemname= "Android:layout_alignparentbottom">True</Item> <Itemname= "Android:layout_alignparentleft">True</Item> <Itemname= "Android:background">@drawable/BUTTON_BG</Item> <Itemname= "Android:drawableleft">@drawable/previous</Item> <Itemname= "Android:text">Previous step</Item> <Itemname= "Android:onclick">Or:</Item> </style>
How do I reference a style?
The application of the style must be in the layout file, for the view of some windows, the following syntax is applied
style= "@style/button_pre_style"
How do I refer to a system's style?
Style= "@android: style/"
Summary: Styles A collection of multiple view properties, when writing layouts, when multiple views have many of the same properties, you can put these same properties together in Styles.xml as a style, and use @style/style_name uniform references in layout files
Then let's explore the subject.
The nature of the theme is also style defined in Styles.xml, but unlike styles, themes are referenced in manifest.xml, and styles are applied in the layout file
How do I define a theme?
Defining a topic's approach is basically the same as defining a style.
<stylename= "Apptheme"Parent= "Appbasetheme"> <Itemname= "Android:textcolor">#ff0000</Item> </style> <stylename= "MyTheme" > <Itemname= "Android:textcolor">#00ff00</Item> <Itemname= "Android:windownotitle">True</Item> </style>
How do I reference a topic?
Topics are referenced in manifest.xml and can be referenced by android:theme= "@style/apptheme" in the properties of application and activity two nodes
The subject referenced in the activity overrides the subject referenced in application, meaning that the subject referenced by application is useful for the entire app's activities, if the individual
Activity refers to a specific topic, and the current activity overrides the subject of the application reference, and the activity theme is displayed.
Is there a priority problem here?
Styles defined within Views >activity reference theme defined styles >application reference theme defined styles
How do I refer to a system theme?
Android:theme= "@android: style/"
System Common topics:
@android: Style/theme.light.notitlebar: no title
@android: Style/theme.light.notitlebar.fullscreen: Fullscreen
@android: Style/theme.dialog: Dialog box
Talk about Android themes and styles today (theme and style)