Styles and themes

Source: Internet
Author: User

A style is a collections of properties that specify the look and format of a view or window.

They allow to separate the design from the content.

Without style XML, we can design it in the layout XML:

 
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textcolor = "#00ff00"
Android: Typeface = "monospace"
Android: text = "@ string/Hello"/>

With style XML, we can turn it:

 
<Textview
Style = "@ style/codefont"
Android: text = "@ string/Hello"/>

A theme is a style applied to an entire activity of application, rather than an individual view.

When a style is applied as a theme, every view in the activity or application will apply each style property that it supports.

Then add an <item> element for each property of that style, with a name that declares the style property and a value to go with it.

 

Defining styles

The root node of the XML file must be <resources>.

For each style you want to create, add a <style> element to the file with a name that uniquely identifies the style.

Each child of the <resource> element is converted into an application resource object at compile-time.

Example:

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "codefont" parent = "@ Android: style/textappearance. Medium">
<Item name = "Android: layout_width"> fill_parent </item>
<Item name = "Android: layout_height"> wrap_content </item>
<Item name = "Android: textcolor"> #00ff00 </item>
<Item name = "Android: typeface"> monospace </item>
</Style>
</Resources>
 
 
 
Inheritance
 
The parent attribute in the <style> element lets you specify a style from which your style shoshould inherit properties.
 
Example
<Style name = "greentext" parent = "@ Android: style/textappearance">
<Item name = "Android: textcolor"> #00ff00 </item>
</Style>
 
 
 
Style Properties
 
The best place to find properties that apply to a specific view is the corresponding class reference, which lists all of the supported attributes.
 
Example

Java. Lang. Object

Using Android. R. ATTR

Public static final int textcolor

Added in API Level 1

Color of text (usually same as colorforeground ).

May be a reference to another resource, in the form"@ [+] [Package:]Type:Name"Or to a theme attribute in the form"? [Package:] [Type:]Name".

May be a color value, in the form"#RGB","#Argb","#Rrggbb", Or"#Aarrggbb".

Constant Value: 16842904 (0x01010098)

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.