Android Style Inheritance

Source: Internet
Author: User

The style acts on a single view or control, extracting common properties for reuse.

There are two ways to inherit a style:

To identify a parent style through the parent

1 <  name= "Greentext"  parent= "@android: style/textappearance">  2     <name= "Android:textcolor"># 00FF00</item>3</style> 

The name of the parent style is prefixed with "." Connect the name of the new style

1 <  name= "codefont.red">2     <Name  = "Android:textcolor">#FF0000</item>  3</style>

Among them, the 2nd way can be unlimited connection sub style implementation of multi-level inheritance.

1 <  name= "CodeFont.Red.Big">2     <Name  = "android:textsize">30sp</item>3  </style>

  

In the 1th way, Android's restrictions on the 2nd approach are that the referenced style must be defined by itself, or that the parent style and child style must be defined within the same program and cannot refer to a third-party or system style. After all, a reference to the system's style is required to add the android: prefix as the namespace. Second, when using a style, the style defined in the 2nd way must refer to its full name, which means it must contain the full prefix and name:

1 < EditText 2     style = "@style/codefont.red.big" 3      />

Android has no limitations on the 1th way of definition, so all styles defined in the 2nd way can be turned into the 1th type:

1 <  name= "Big"  parent= "codefont.red">2      <name= "android:textsize">30sp</Item  >3</style>

  

When the parent style is specified with parent, the prefix is no longer functional, just as the name of the style. In other words, the Android style does not support multiple inheritance, only one layer at a to inherit.

  

Resources

Style inheritance relationship in Android

  

  

  

.

  

Android Style Inheritance

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.