Android official documentation: (3) resources-3.6.8 Style

Source: Internet
Author: User

A style resource defines the format and look for a UI. A style can be applied to an individualView(From within a layout file) or toan entireActivityOr application (from within the manifest file ).

For more information about creating and applying styles, please readStyles and Themes.

Note:A style is a simple resource that is referencedusing the value provided innameAttribute (not the name of the XML file). Assuch, you can combine style resources with other simple resources in the one XML file, under one<resources>Element.

File location:
res/values/filename.xml
The filename is arbitrary. The element's nameWill be used as the resource ID.
Resource reference:
In XML: @[package:]style/style_name
Syntax:
<?xml version="1.0" encoding="utf-8"?><resources>    <style        name="style_name"        parent="@[package:]style/style_to_inherit">        <item            name="[package:]style_property_name"            >style_value</item>    </style></resources>
Elements:
<resources>
Required.This must be the root node.

No attributes.

<style>
Defines a single style. Contains <item>Elements.

Attributes:

name
String. Required. A name for the style, which is used as theresource ID to apply the style to a View, Activity, or application.
parent
Style resource. Reference to a style from which thisstyle shoshould inherit style properties.
<item>
Defines a single property for the style. Must be a child of <style>Element.

Attributes:

name
Attribute resource. Required. The name of the style propertyto be defined, with a package prefix if necessary (for example android:textColor).
Example:
XML file for the style (saved in res/values/):
<?xml version="1.0" encoding="utf-8"?><resources>    <style name="CustomText" parent="@style/Text">        <item name="android:textSize">20sp</item>        <item name="android:textColor">#008</item>    </style></resources>
XML file that applies the style to TextView(Saved in res/layout/):
<?xml version="1.0" encoding="utf-8"?><EditText    style="@style/CustomText"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:text="Hello, World!" />

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.