Android article---Styles and themes common usage possible suspects summary

Source: Internet
Author: User
Tags naming convention

The difference between 1.style and theme: In short, style refers to the style of a UI control in Android, while themes refers to an activity interface in Android or a whole Android app. The range of theme is larger than the range of style. 2.style Inheritance Usage: (all by the author according to the official document Pro-Test, can be used with confidence, note: the definition of the style is in/res/values/style.xml, and the style is used in the Activity layout file)
  • For inheriting the original Android style, use the following block of code, which means to change the TextColor property in the Textappearance style of the Android system to green and the other properties unchanged:
    <name= "Greentext"  parent= "@android: Style/textappearance" >        <  name= "Android:textcolor">#00FF00</Item >    </ style >

    The style is then referenced in the UI control through the value of the <style> label's Name property, for example, referencing the style code block defined above in <TextView> as follows:
    < TextView         Android:text = "Hello style"         android:layout_width= "Match_parent"        android:layout_height= "Wrap_ Content "        style=" @style/greentext "        />

  • There are two ways to inherit a custom style, for example, if we already have a custom-defined parent style, the code is as follows:
    <stylename= "Codefont"Parent= "@android: Style/textappearance.medium">        <Itemname= "Android:layout_width">Fill_parent</Item>        <Itemname= "Android:layout_height">Wrap_content</Item>        <Itemname= "Android:textcolor">#00FF00</Item>        <Itemname= "Android:typeface">Monospace</Item>    </style>

    The first is the same as the previous method, with the parent property, followed by the parents style, for example:
    <name= "Red"  parent= "@style/codefont">         <name= "Android:textcolor">#FF0000</  Item>    </style>

    The second is to inherit custom parent style-specific ways, using symbols. Represents an inheritance relationship. For example:
    <name= "codefont.red">        <name = "Android:textcolor" >#FF0000</item>    </style >

    The style is still used in the UI control by referencing the style through the value of the <style> tag's Name property, note that the name is the value of the Name property in the <style> tag
3. When do I use @android:style with @style? @android: Style is reference to the style of the Android system, and @style is a reference to our own style in the/res/values/styles.xml file, the actual principle is this, the format of the resource reference is this:
@[package:]style/style_name

When a style is referenced in a UI control, it is referenced by name, not the file name of the XML, and the file name of the XML can be arbitrary, but in order to see the naming convention, the style is defined for styles.xml. The Android native style is in a package called Android, so the reference is written as @android:style.

Android article---Styles and themes common usage possible suspects summary

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.