- A style is a set of one or more formatting attributes that you can apply as a unit to single elements in your layout XML file(s). For example, you could define a style that specifies a certain text size and color, then apply it to instances of a certain type of View element.
- A theme is a set of one or more formatting attributes that you can apply as a unit to all activities in an application or just a single activity. For example, you could define a theme that sets specific colors for the window frame and the panel foreground and background, and sets text sizes and colors for menus, then apply it to the activities of your application.
- Create a file named
styles.xml
in the your application'sres/values
directory. Add a root
node. - For each style or theme, add a
element with a unique
name
and, optionally, aparent
attribute. The name is used for referencing these styles later, and the parent indicates what style resource to inherit from. - Inside the
element, declare format values in one or more
element(s). Each
identifies its style property with aname
attribute and defines its style value inside the element. - You can then reference the custom resources from other XML resources, your manifest or application code.
elements to set specific formatting values for the style. The name
attribute in the item
can refer to a standard string, a hex color value, or a reference to any other resource type.parent
attribute in the
element. This attribute lets you specify a resource from which the current style will inherit values. The style can inherit from any type of resource that contains the style(s) you want. In general, your styles should always inherit (directly or indirectly) from a standard Android style resource. This way, you only have to define the values that you want to change.
Here's how you would reference the custom style from an XML layout, in this case, for an EditText element:
Now this EditText widget will be styled as defined by the XML example above.
0 comments :
Post a Comment