Style, ATTR, theme in Android

Source: Internet
Author: User

In conclusion, do not forget

1) style is similar to CSS and used to define the attributes of view and other UI elements, such as layout_width. It can be referenced by @ style/name in layout XML.

2) If you want to add custom attributes to a style, you can define them in ATTR. An ATTR includes the name and format attributes, which can be referenced by @ ATTR/name in the style.

You can also define an attribute set in ATTR and define it with the declare-styleable tag. This attribute set is used in the view constructor.

Public View (context, attributeset attrs, int defstyle );

View, you can know the attributes in defstyle In the constructor.

The reference of an attribute set is different from that of a single attribute. It is referenced by R. styleable. Name.

3) theme is generally for activity and takes effect globally. Generally, style is specified in theme, which is generally completed by an attribute defined in ATTR.

For example, define the autocomplettextviewstyle attribute in ATTR and specify

<Item name = "autocompletetextviewstyle"> @ Android: style/widget. autocompletetextview </item>

In this way, you can use R. ATTR. autocompletetextviewstyle in the view constructor to obtain the style specified in theme.

In public view (context, attributeset attrs, int defstyle );

In, defstyle can be either a style: R. style. Name or R. ATTR. name. For the latter, you must specify the attribute value in theme.

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.