首页 > 代码库 > Styles and Themes

Styles and Themes

Styles and Themes

  A 样式 is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.

  A theme is a style applied to an entire Activity or application, rather than an individual View (as in the example above). When a style is applied as a theme, every View in the Activity or application will apply each style property that it supports.

 

  To create a set of styles, save an XML file in the res/values/ directory of your project. The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder.

  The root node of the XML file must be <resources>.

  

  Each child of the <resources> element is converted into an application resource object at compile-time, which can be referenced by the value in the <style> element‘s name attribute. This example style can be referenced from an XML layout as @style/CodeFont

  If you want to inherit from styles that you‘ve defined yourself, you do not have to use the parent attribute. Instead, just prefix the name of the style you want to inherit to the name of your new style, separated by a period. For example, to create a new style that inherits the CodeFont style defined above, but make the color red, you can author the new style like this:

  技术分享

参考:http://www.android-doc.com/guide/topics/ui/themes.html

Styles and Themes